cn.easyproject.easycommons.commondao.util.EasyCriteria Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of easycommondao-jpa-hibernate3 Show documentation
Show all versions of easycommondao-jpa-hibernate3 Show documentation
Java ORM Common DAO(Data Access Object), eliminate the interface and implements of DAO.
The newest version!
package cn.easyproject.easycommons.commondao.util;
/**
* 按条件查询抽象父类(可以结合分页PageBean使用)
*
* SysUserCriteria Demo:
*
*
* public class SysUserCriteria extends EasyCriteria implements java.io.Serializable {
* // 1. Criteria field
* private String name;
* private String realName;
* private Integer status; // 0 is ON; 1 is OFF; 2 is REMOVED
*
* // 2. Constructor
* public SysUserCriteria() {
* }
*
* public SysUserCriteria(String name, String realName, Integer status) {
* super();
* this.name = name;
* this.realName = realName;
* this.status = status;
* }
*
* // 3. Condition genertator abstract method implements
* public String getCondition() {
* values.clear(); // **Must clear old values**
* StringBuffer condition = new StringBuffer();
* if (StringUtils.isNotNullAndEmpty(this.getName())) {
* condition.append(" and name like ?");
* values.add("%" + this.getName() + "%");
* }
* if (StringUtils.isNotNullAndEmpty(this.getRealName())) {
* condition.append(" and realName like ?");
* values.add("%" + this.getRealName() + "%");
* }
* if (StringUtils.isNotNullAndEmpty(this.getStatus())) {
* condition.append(" and status=?");
* values.add(this.getStatus());
* }
* return condition.toString();
* }
*
* // 4. Setters&Getters...
*
* }
*
*
* @author Ray
* @author [email protected]
* @author easyproject.cn
* @since 1.0.0
*/
import java.util.HashMap;
import java.util.Map;
/**
* 按条件查询抽象父类(可以结合分页PageBean使用)
* @author easyproject.cn
* @version 1.0
*
* SysUser查询标准条件类使用Demo:
public class SysUserCriteria extends EasyCriteria implements java.io.Serializable {
// 1. 添加条件属性
private String name;
private String realName;
private Integer status; // 用户状态:0启用;1禁用;2删除
// 2. 生成构造方法
public SysUserCriteria() {
}
public SysUserCriteria(String name, String realName, Integer status) {
super();
this.name = name;
this.realName = realName;
this.status = status;
}
// 3. 条件生成抽象方法实现
public String getCondition() {
values.clear(); //清除条件数据
StringBuffer condition = new StringBuffer();
if (StringUtils.isNotNullAndEmpty(this.getName())) {
condition.append(" and name like :name");
values.put("name", "%" + this.getName() + "%");
}
if (StringUtils.isNotNullAndEmpty(this.getRealName())) {
condition.append(" and realName like :realName");
values.put("realName", "%" + this.getRealName() + "%");
}
if (StringUtils.isNotNullAndEmpty(this.getStatus())) {
condition.append(" and status=:status");
values.add("status", this.getStatus());
}
return condition.toString();
}
// 4. Setters&Getters...
}
*/
public abstract class EasyCriteria {
protected Map values = new HashMap();
public abstract String getCondition() ;
public Map getValues() {
return values;
}
public void setValues( Map values) {
this.values = values;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy