多表查询所用到的用来构造list的 java类 SimpleInformation.java
package com.business;
import java.util.Date;
public class SimpleInformation {
private Integer infoid;
private Integer punishid;
private String subject; // 标题
private String reason; // 原因
private String result; // 结果
private Integer complaintresult;
private Integer readcount;// 阅读次数
private Integer commentcount;// 评论次数
private Integer scorenumber;// 评分分数
private Integer residualDay;// 收费剩余时间(天);
private Date publishtime;// 发表时间
private Integer confineday;// 关屋天数
private Date punishtime;// 处罚时间
private Integer reportCount;// 举报次数
private Date reportToResume; // 恢复发表时间;
private String confinereason;// 关屋原因
private String deductionreason;// 扣除积分
private String adjustreason;// 调整点数
private boolean deduction;//是否扣积分
private boolean confine;//是不关小黑屋
private boolean adjust;//是否积分调整
public SimpleInformation() {
}
// 构造器
public SimpleInformation(Integer infoid, Integer punishid, String subject,
String result, Integer complaintresult, Integer readcount,
Date publishtime, String confinereason, String deductionreason,
String adjustreason,boolean deduction,boolean confine,boolean adjust) {
this.infoid = infoid;
this.punishid = punishid;
this.subject = subject;
this.result = result;
this.complaintresult = complaintresult;
this.readcount = readcount;
this.publishtime = publishtime;
this.confinereason = confinereason;
this.deductionreason = deductionreason;
this.adjustreason = adjustreason;
this.deduction = deduction;
this.confine = confine;
this.adjust = adjust;
}
public String getConfinereason() {
return confinereason;
}
public void setConfinereason(String confinereason) {
this.confinereason = confinereason;
}
public Date getReportToResume() {
return reportToResume;
}
public void setReportToResume(Date reportToResume) {
this.reportToResume = reportToResume;
}
public Integer getReportCount() {
return reportCount;
}
public void setReportCount(Integer reportCount) {
this.reportCount = reportCount;
}
public Date getPunishtime() {
return punishtime;
}
public void setPunishtime(Date punishtime) {
this.punishtime = punishtime;
}
public Integer getConfineday() {
return confineday;
}
public void setConfineday(Integer confineday) {
this.confineday = confineday;
}
public Integer getInfoid() {
return infoid;
}
public void setInfoid(Integer infoid) {
this.infoid = infoid;
}
public Integer getPunishid() {
return punishid;
}
public void setPunishid(Integer punishid) {
this.punishid = punishid;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public Integer getComplaintresult() {
return complaintresult;
}
public void setComplaintresult(Integer complaintresult) {
this.complaintresult = complaintresult;
}
public Integer getReadcount() {
return readcount;
}
public void setReadcount(Integer readcount) {
this.readcount = readcount;
}
public Integer getCommentcount() {
return commentcount;
}
public void setCommentcount(Integer commentcount) {
this.commentcount = commentcount;
}
public Integer getScorenumber() {
return scorenumber;
}
public void setScorenumber(Integer scorenumber) {
this.scorenumber = scorenumber;
}
public Integer getResidualDay() {
return residualDay;
}
public void setResidualDay(Integer residualDay) {
this.residualDay = residualDay;
}
public Date getPublishtime() {
return publishtime;
}
public void setPublishtime(Date publishtime) {
this.publishtime = publishtime;
}
public String getDeductionreason() {
return deductionreason;
}
public void setDeductionreason(String deductionreason) {
this.deductionreason = deductionreason;
}
public String getAdjustreason() {
return adjustreason;
}
public void setAdjustreason(String adjustreason) {
this.adjustreason = adjustreason;
}
public boolean isDeduction() {
return deduction;
}
public void setDeduction(boolean deduction) {
this.deduction = deduction;
}
public boolean isConfine() {
return confine;
}
public void setConfine(boolean confine) {
this.confine = confine;
}
public boolean isAdjust() {
return adjust;
}
public void setAdjust(boolean adjust) {
this.adjust = adjust;
}
}
DAO代码 调用构造器得到 list
@Transactional
public class InformationDBImpl implements InformationDB{
@SuppressWarnings("unchecked")
public List<SimpleInformation> findByPunish(String type, String userid,
Pagination pagination) {
List list = new ArrayList();
Query query1 = em
.createQuery("select count(m) from Information m,Punish p where m.infoid = p.infoid and m.type =:type and m.author.id =:userid");
query1.setParameter("type", type);
query1.setParameter("userid", userid);
Long count = (Long) query1.getSingleResult();//分页统计
pagination.setTotal(count.intValue());
//运用构造器
String queryPunishfree = " select new com.business.SimpleInformation(m.infoid ,p.punishid,m.subject,p.result,p.complaintresult,m.readcount,m.publishtime,p.confinereason,p.deductionreason,p.adjustreason,p.confine,p.deduction,p.adjust)"
+ " from Information m,Punish p where m.infoid = p.infoid "
+ " and m.type =:type and m.author.id =:userid";
try {
if (type.trim().equals("0")) {
Query query = em.createQuery(queryPunishfree);// 收费查询
query.setParameter("type", type);
query.setParameter("userid", userid);
query.setFirstResult(pagination.getStartIndex());//分页
query.setMaxResults(pagination.getSize());
list = query.getResultList();
System.out.println("========queryPunishfree0 ="
+ queryPunishfree);
} else {
Query query = em.createQuery(queryPunishfree);// 免费查询
query.setParameter("type", type);
query.setParameter("userid", userid);
query.setFirstResult(pagination.getStartIndex());
query.setMaxResults(pagination.getSize());
list = query.getResultList();
System.out.println("========queryPunishfree1 ="
+ queryPunishfree);
}
} catch (RuntimeException re) {
throw re;
}
return list;
}
}
service 代码:
public List<SimpleInformation> findByPunish(String type, String userid,
Pagination pagination) {
return informationDB.findByPunish(type, userid, pagination);
}
action 代码:
public class InformationAction extends ActionSupport
private List<SimpleInformation> simpleinfos;
this.simpleinfos = service.findByPunish(type, userid, pagination); //得到构造器list
setPager(pagination.makePageList()); //分页设置
result = "success"; // 处罚 --struts.xml result="success";
}
分享到:
相关推荐
赠送jar包:hibernate-jpa-2.1-api-1.0.2.Final.jar; 赠送原API文档:hibernate-jpa-2.1-api-1.0.2.Final-javadoc.jar; 赠送源代码:hibernate-jpa-2.1-api-1.0.2.Final-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:hibernate-jpa-2.1-api-1.0.2.Final.jar; 赠送原API文档:hibernate-jpa-2.1-api-1.0.2.Final-javadoc.jar; 赠送源代码:hibernate-jpa-2.1-api-1.0.2.Final-sources.jar; 赠送Maven依赖信息文件:...
hibernate-jpa-2.1-api-1.0.0.final-sources.jar 源码 hibernate-jpa-2.1-api-1.0.0.final-sources.jar 源码
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-jpa-2.1-api-1.0.0.final.jar.zip,内含hibernate-jpa-2.1-api-1.0.0.final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar官方下载,请放心使用
hibernate-jpa-2.0-api-1.0.1.Final-sources.jar hibernate jpa 源代码
java.lang.NoClassDefFoundError: javax/persistence/spi/ProviderUtil 或javax/persistence/entitylistener问题
多表查询所用到的用来构造list的java类,用于演示在 jpa SQL 查询中如何使用自定义构造器。
hibernate-jpa-2.0-api-1.0.1.Final-sources
java运行依赖jar包
hibernate-jpa-2.1-api-1.0.0.final-sources.jar.zip的源代码
springJpa单标递归树形结构
antlr-2.7.6.jar, cglib-2.2.jar, commons-collections-3.1.jar, ...hibernate-jpa-2.0-api-1.0.0.Final.jar, javassist-3.9.0.GA.jar, jta-1.1.jar, slf4j-api-1.6.1.jar, slf4j-log4j12-1.6.1.jar
java运行依赖jar包
实用JPA开发指南实用JPA开发指南实用JPA开发指南实用JPA开发指南实用JPA开发指南实用JPA开发指南实用JPA开发指南实用JPA开发指南
JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询...
NULL 博文链接:https://ylq365.iteye.com/blog/1664599