java下拉框转换公共方法
1. 下拉框实例类


import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; public class CodeNameItem { /**
* Build a CodeNameItem instance from an object with given mapping properties.
*
* @param obj
* @param idProps
* @param codeProps
* @param nameProps
* @param descProps
* @return
*/
public static CodeNameItem fromObject(Object obj, String idProps, String codeProps, String nameProps,
String descProps) {
Long id;
try {
id = (Long) PropertyUtils.getProperty(obj, idProps);
String code = StringUtils.defaultString((String) PropertyUtils.getProperty(obj, codeProps));
String name = StringUtils.defaultString((String) PropertyUtils.getProperty(obj, nameProps));
String description = StringUtils.defaultString((String) PropertyUtils.getProperty(obj, descProps));
return new CodeNameItem(id, null, code, name, description, description);
} catch (Exception e) {
e.printStackTrace();
}
return null;
} /**
* Build a CodeNameItem instance from an object with given mapping properties.
*
* @param obj
* @param idProps
* @param codeProps
* @param nameProps
* @param descProps
* @param markStatus 启用
* @return
*/
public static CodeNameItem fromObject(Object obj, String idProps, String codeProps, String nameProps,
String descProps,String markStatus) {
Long id;
try {
id = (Long) PropertyUtils.getProperty(obj, idProps);
String code = StringUtils.defaultString((String) PropertyUtils.getProperty(obj, codeProps));
String name = StringUtils.defaultString((String) PropertyUtils.getProperty(obj, nameProps));
String description = StringUtils.defaultString((String) PropertyUtils.getProperty(obj, descProps));
Object property=null;
try {
property=PropertyUtils.getProperty(obj, markStatus);
}catch(Exception e) {
property=true;
}
//判断人员markStatus字段类型
Boolean status=null;
if(property instanceof Boolean) {
status=(Boolean)PropertyUtils.getProperty(obj, markStatus);
}else if(property instanceof Integer) {
Integer num=(Integer)property;
status=num==1?true:false;
}else if(property instanceof Long) {
Integer num=1;
status=property.equals(num.longValue())?true:false;
}else if(property instanceof String) {
status = BooleanUtils.toBoolean((String)property);
}else {
//其他类型默认都是启用的
status=true;
}
return new CodeNameItem(id, null, code, name, description, description,status);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private Long id = null; private String type; private String code; private String name;
private String description; /**
* @Fields descriptionEn : CodeList中的英文描述,2013-01-23,yangzhi
*/
private String descriptionEn;
private String funcCn;// BIZCodeList功能中文描述 private String funcEn; // BIZCodeList 功能英文描述 public CodeNameItem() {
} public CodeNameItem(Long id, String type, String code, String name, String description) {
super();
this.id = id;
this.type = type;
this.code = code;
this.name = (name == null || "".equals(name)) ? "" : name;
this.description = (description == null || "".equals(description)) ? "" : description;
} /**
* 创建一个新的实例 CodeNameItem,此构造方法能创建CodeList中有英文描述
*
* @param id
* @param type
* @param code
* @param name
* @param description
* @param descriptionEn
*/
public CodeNameItem(Long id, String type, String code, String name, String description, String descriptionEn) {
super();
this.id = id;
this.type = type;
this.code = code;
this.name = (name == null || "".equals(name)) ? "" : name;
this.description = (description == null || "".equals(description)) ? "" : description;
this.descriptionEn = (descriptionEn == null || "".equals(descriptionEn)) ? "" : descriptionEn;
} /**
* 创建一个新的实例 CodeNameItem,此构造方法能创建codelist启用不启用
*
* @param id
* @param type
* @param code
* @param name
* @param description
* @param descriptionEn
*/
public CodeNameItem(Long id, String type, String code, String name, String description, String descriptionEn,Boolean markStatus) {
super();
this.id = id;
this.type = type;
this.code = code;
this.name = (name == null || "".equals(name)) ? "" : name;
this.description = (description == null || "".equals(description)) ? "" : description;
this.descriptionEn = (descriptionEn == null || "".equals(descriptionEn)) ? "" : descriptionEn;
} /**
* 创建一个新的实例 CodeNameItem,此构造方法能创建CodeList中有英文描述
*
* @param id
* @param type
* @param code
* @param name
* @param description
* @param descriptionEn
* @param funcCn
* @param funcEn
*/
public CodeNameItem(Long id, String type, String code, String name, String description, String descriptionEn,
String funcCn, String funcEn) {
super();
this.id = id;
this.type = type;
this.code = code;
this.name = (name == null || "".equals(name)) ? "" : name;
this.description = (description == null || "".equals(description)) ? "" : description;
this.descriptionEn = (descriptionEn == null || "".equals(descriptionEn)) ? "" : descriptionEn;
this.funcCn = (funcCn == null || "".equals(funcCn)) ? "" : funcCn;
this.funcEn = (funcEn == null || "".equals(funcEn)) ? "" : funcEn;
} public int compare(CodeNameItem item) {
return (this.getCode() + this.getName()).compareToIgnoreCase(item.getCode() + item.getName());
} @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (getClass() != obj.getClass())
return false;
final CodeNameItem other = (CodeNameItem) obj;
if (code == null) {
if (other.code != null)
return false;
} else if (!code.equals(other.code))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
} public String getCode() {
return code;
} public String getDescription() {
return description;
} public String getDescriptionEn() {
return descriptionEn;
} public String getFuncCn() {
return funcCn;
} public String getFuncEn() {
return funcEn;
} public Long getId() {
return id;
} public String getLabel() {
return this.name;
} public String getName() {
return name;
} public String getType() {
return type;
} public String getValue() {
return this.code;
} @Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((code == null) ? 0 : code.hashCode());
result = PRIME * result + ((name == null) ? 0 : name.hashCode());
return result;
} public void setCode(String code) {
this.code = code;
} public void setDescription(String description) {
this.description = description;
} public void setDescriptionEn(String descriptionEn) {
this.descriptionEn = descriptionEn;
} public void setFuncCn(String funcCn) {
this.funcCn = funcCn;
} public void setFuncEn(String funcEn) {
this.funcEn = funcEn;
} public void setId(Long id) {
this.id = id;
} public void setName(String name) {
this.name = name;
} public void setType(String type) {
this.type = type;
} public String toString() {
return "id:" + id + "\ttype:" + type + "\tcode:" + code + "\tname:" + name + "\tdescription:" + description;
}
}
2.结果实例转换类


package org.testzl.zlqtms.controller.datasource; import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors; public class CodeNameItemConvertor<T> {
private List<T> list; public CodeNameItemConvertor(List<T> list) {
this.list = list;
} public <U> List<U> map(Function<? super T, ? extends U> converter) {
if (list == null)
return null;
return list.stream().map(converter::apply).collect(Collectors.toList());
} }
3.使用案例


@GetMapping("xxxxx")
public List<CodeNameItem> tbClaimTypes(@RequestParam(required=false) String q) {
BaseSearchViewModel baseSearchViewModel = new BaseSearchViewModel();
baseSearchViewModel.setLimit(200);
TbClaimType tbTrouble = new TbClaimType();
tbTrouble.setTypeCode(q);
tbTrouble.setCompany(userCompanyUtil.getUserCompany());
GridResult<TbClaimType> pageListByCode = tbClaimTypeService.query(baseSearchViewModel, tbTrouble);
return new CodeNameItemConvertor<TbClaimType>((List<TbClaimType>)pageListByCode.getBody())
.map(p -> CodeNameItem.fromObject(p, "id", "typeCode", "descZh", "descEn"));
}
java下拉框转换公共方法的更多相关文章
- jquery操作select下拉框的各种方法,获取选中项的值或文本,根据指定的值或文本选中select的option项等
简介jquery里对select进行各种操作的方法,如联动.取值.根据值或文本来选中指定的select下拉框指定的option选项,读取select选中项的值和文本等. 这一章,站长总结一下jquer ...
- Selenium+java - 下拉框处理
常见下拉框也分两种:一种是标准控件和非标准控件(一般为前端开发人员自己封装的下拉框),本篇文章中将重点讲解标准下拉框操作. 1.Select提供了三种选择某一项的方法 select.selectByI ...
- java下拉框,滚动条
package com.soft.test; /** * 下拉列表.下拉框.滚动条的使用 */ import javax.swing.*; import java.awt.*; public clas ...
- jquery操作select下拉框的多种方法(选中,取值,赋值等)
Query获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Sel ...
- [selenium]选取下拉框内容的方法
说明:本文章主要是对select元素操作的讲解,非select元素的下拉框需要另外分析 1.select元素示例: 2.select下拉框选取的3种方法 WebElement selector = d ...
- java 下拉框级联及相关(转)
ActionLintsner都实现此接口,其它监听器可以监听的事件都可以被它捕获 public interface ActionListener extends EventListenerThe li ...
- angular 中自己常用的下拉框获取值方法
方法一 HTML页中 <select name="" id="if02" data-first-option="true" (chan ...
- PHP下拉框选择的实现方法
实现 第一种PHP下拉框实现方法: < ?php //提交下拉框; //直接饱触发onchange事件的结果 $id=$_GET['myselect']; // myselect 为locati ...
- easyUI combobox下拉框很长,easyUI combobox下拉框如何显示滚动条的解决方法
如下图,combobox下拉框里内容很多时,会导致下拉框很长,很不美观. 如何使得combobox下拉框显示滚动条 方法:把属性panelHeight:"auto"注释掉即可. $ ...
随机推荐
- [BUUCTF]REVERSE——[WUSTCTF2020]Cr0ssfun
[WUSTCTF2020]Cr0ssfun 附件 步骤: 例行检查,无壳儿,64位程序,直接ida载入,检索程序里的字符串,根据提示跳转 看一下check()函数 内嵌了几个检查的函数,简单粗暴,整理 ...
- 『与善仁』Appium基础 — 25、APP模拟手势高级操作
目录 1.手指轻敲操作 2.手指按下和抬起操作 3.等待操作 4.手指长按操作 5.手指移动操作 6.综合练习 APP模拟手势的动作都被封装在TouchAction类中,TouchAction是App ...
- CF934A A Compatible Pair 题解
Content 有两个数列 \(A\) 和 \(B\),\(A\) 数列里面有 \(n\) 个元素,\(B\) 数列里面有 \(m\) 个元素,现在请从 \(A\) 数列中删除一个数,使得 \(A\) ...
- LuoguP7478 【A】StickSuger 题解
Content 给定一个长度为 \(n\) 的仅包含小写字母的字符串 \(s\),请找到一个二元组 \((i,j)\)(\(i<j\))使得在交换字符串 \(s\) 的第 \(i\) 个和第 \ ...
- JAVA实现office文档(word、excel、ppt等)、压缩包在线预览,支持禁止下载功能、支持PC和手机
我们使用的是永中的第三方服务.支持直接转换文档的线上地址,也可以直接把文档上传到官方服务器上 官方文档地址:https://www.yozodcs.com/page/help.html#link152 ...
- 【LeetCode】299. Bulls and Cows 解题报告(Python)
[LeetCode]299. Bulls and Cows 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题 ...
- 第三十四个知识点:描述攻击离散对数问题的baby-step/Giant-step方法
第三十四个知识点:描述攻击离散对数问题的baby-step/Giant-step方法 Baby-step/Giant-step是Dnaiel Shanks为解决DLP问题开发的算法.DLP问题已经是许 ...
- CLION 使用自己的makefile来运行
之前参考过这里和这里,都是说要使用add_custom_target,无奈看不懂 但是前一篇里说它参考的是stackoverflow上的回答,去原帖里发现后来更新的第二高票答案!!!非常好用!!! 在 ...
- [opencv]KAZE、AKAZE特征检测、匹配与对象查找
AkAZE是KAZE的加速版 与SIFT,SUFR比较: 1.更加稳定 2.非线性尺度空间 3.AKAZE速度更加快 4.比较新的算法,只有Opencv新的版本才可以用 AKAZE局部匹配介绍 1.A ...
- 编写Java程序_输入一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
要求: 输入一个5位数,判断它是不是回文数.即12321是回文数,个位与万位相同,十位与千位相同. 实现代码: package kaoshi; import java.util.Scanner; pu ...