实体类:
@Entity
@Table(name = "xxxxx")
public class WzInitializeStoreInfo extends EntityBean{
private static final long serialVersionUID = 1L;
//字段都需要get、set方法
@Id
@Column(name = "INCODE")
private Long incode;
@Column(name = "BATCH_ID")
private Long batchId;
@Column(name = "VALID_DATE")
private Timestamp validDate; //其他表的字段
@Transient
private String modelDesc;//无参参构造方法
public WzInitializeStoreInfo(){}
//有参构造方法
public WzInitializeStoreInfo(Long incode, Long batchId,
String modelDesc,Date validDate) {
super();
this.incode = incode;
this.batchId = batchId;
this.modelDesc=modelDesc;
this.validDate = (Timestamp)validDate;
}
public Long getIncode() {
return incode;
}
public void setIncode(Long incode){
this.incode = incode;
}
public String getModelDesc() {
return modelDesc;
} public void setModelDesc(String modelDesc) {
this.modelDesc = modelDesc;
} @Override
public Record exportToRecord() {
EntityMetaData metaData = EntityMetaDataUtil.getEntityMetaData(this.getClass().getName());
if (metaData == null) {
new BaseRunException("Java类"+this.getClass().getName()+"没有元数据信息!不能导出为Record!").handle();
}
Record record = PrintUtil.genEmptyExportRecord(metaData);
record.set("INCODE", this.incode);
record.set("BATCH_ID", this.batchId);
return record;
}
}
Ipml
@Component("wzInitializeStoreInfoDetailService")
public class WzInitializeStoreInfoDetailServiceImpl implements WzInitializeStoreInfoDetailService {
IDAO supplyDAO = JPAUtil.useJPATool("SupplyChainJPAToolDAO");//仓储用户
public List<WzInitializeStoreInfo> retrieve(QueryParamList param, PageInfo pageInfo,SortParamList sort) throws BaseRunException {
StringBuffer jpql=new StringBuffer();
jpql.append("select new com.haiyisoft.entity.wz.WzInitializeStoreInfo(w.incode,w.batchId,c.modelDesc,w.validDate)");
jpql.append(" from WzInitializeStoreInfo w,WzCode c where w.incode=c.incode " +
"AND w.storeId in ("+StoreCommonUtil.getLowStoreStr(((AdminView)ContextUtil.getUserView()).getOrgPartyId())+")"); //查询自己仓库的数据
}
if(param.get("batchId")!=null){
jpql.append(" and w.batchId=:batchId");
}
if(param.get("modelDesc")!=null){
jpql.append(" and c.modelDesc like :modelDesc"); 76 }
jpql.append(" order by w.batchId desc");
List<Object> list=supplyDAO.find(jpql.toString(),param, sort,pageInfo);
List<WzInitializeStoreInfo> siteList=new ArrayList<WzInitializeStoreInfo>();
for(int i=0;i<list.size();i++){
siteList.add((WzInitializeStoreInfo)list.get(i));
}
return siteList;
}
}
注意事项:
①构造方法的字段名、顺序、个数,要与查询语句的一致
②查询方法中要加入主键
③在实体类中要有无参的构造方法和有参数的构造方法
④如果代码中涉及到时间类型,注意时间类型的转换
⑤ com.haiyisoft.entity.wz.WzInitializeStoreInfo实体类全路径
模糊查询:
if(param.get("wzName")!=null){ ①jpql.append(" and c.wzName like "+"'"+param.get("wzName").getValue()+"'"); 或者: ②jpql.append(" and c.wzName like :wzName ''); } ②List<Object> list=supplyDAO.find(jpql.toString(), param,sort,pageInfo); 注意 ①和②的差别,①如果传参数会报找不到相应字段的错误
查询 适用于前台下拉Integer类型报错
if (param.get("laiyuanType")!=null) {
String laiyuan=param.get("laiyuanType").getValue().toString();
param.get("laiyuanType").setValue(Integer.valueOf(laiyuan));
jpql.append("and w.laiyuanType=:laiyuanType");
}