多表查询所用到的用来构造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.1-api-1.0.0.final.jar`是Hibernate对JPA 2.1规范的实现库,它使得开发者能够使用Hibernate的高效功能同时遵循JPA规范。 **1. Hibernate与JPA的关系** Hibernate最初作为一个独立的ORM框架,后来...
hibernate-jpa-2.0-api-1.0.1.Final-sources.jar hibernate jpa 源代码
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar官方下载,请放心使用
在JPA中,构造器的使用是实现对象映射和数据查询的一种高效方式,特别是对于复杂的查询场景,如多表查询。 构造器允许我们在创建实体类的实例时传入参数,这些参数可以用于初始化对象的状态。在JPA中,我们可以利用...
java.lang.NoClassDefFoundError: javax/persistence/spi/ProviderUtil 或javax/persistence/entitylistener问题
JPA支持多种关系映射,如一对一(@OneToOne)、一对多(@OneToMany)、多对一(@ManyToOne)和多对多(@ManyToMany)。这些注解用于定义实体之间的关联,并可以配置关联的字段、级联操作等。 5. **查询操作** JPA...
java运行依赖jar包
在本示例中,我们将探讨如何使用Spring JPA来实现单表递归树形结构。 首先,我们需要理解递归树形结构。在数据库中,树形结构通常通过自关联来表示,即一个表的某个字段引用该表自身,形成一个层级关系。对于单表...
这个源码包"hibernate-jpa-2.0-api-1.0.1.Final-sources"包含了完整的源代码,可以帮助我们深入了解其内部机制,从而更好地应用在实际项目中。 1. **JPA简介**:Java Persistence API(JPA)是Java平台上的一个标准...
本篇文章将重点围绕“hibernate-jpa-2.1-api-1.0.0.final-sources.jar.zip”这一压缩包,深入解析Hibernate对JPA 2.1 API的实现,以期帮助读者深入理解其内部机制。 JPA(Java Persistence API)是Java平台上的一个...
【标题】"myfaces-extcdi-jpa1-module-impl-1.0.6.zip" 涉及的是一款开源项目中的模块实现,主要关注MyFaces扩展CDI(Contexts and Dependency Injection)与JPA(Java Persistence API)的集成。MyFaces是Apache...
通过深入理解并灵活运用这些知识点,开发者可以有效地利用JPA进行数据持久化操作,提高开发效率,并降低与数据库交互的复杂性。EJB3_JPA.doc和JPA_Basic.pdf可能包含了更详细的教程和实例,帮助读者进一步掌握JPA的...
JPQL是JPA提供的面向对象的查询语言,类似于SQL但不直接操作表和列。例如,获取所有用户: ```java String query = "SELECT u FROM User u"; TypedQuery<User> typedQuery = em.createQuery(query, User.class);...
**JPA 开发文档——全面解析** 1. **发展中的持久化技术** ...通过理解JPA的发展背景、体系架构、Entity Bean的定义和管理,以及EntityManager和JPA查询的使用,开发者能够更高效地实现数据持久化。
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