做出相应的操作之后,我们的实体类以及映射文件就自动生成完毕了:
public class Complain implements java.io.Serializable { // Fields private String compId; private String compCompany; private String compName; private String compMobile; private Boolean isNm; private Timestamp compTime; private String compTitle; private String toCompName; private String toCompDept; private String compContent; private String state; private Set complainReplies = new HashSet(0); // Constructors /** default constructor */ public Complain() { } /** minimal constructor */ public Complain(String compTitle) { this.compTitle = compTitle; } /** full constructor */ public Complain(String compCompany, String compName, String compMobile, Boolean isNm, Timestamp compTime, String compTitle, String toCompName, String toCompDept, String compContent, String state, Set complainReplies) { this.compCompany = compCompany; this.compName = compName; this.compMobile = compMobile; this.isNm = isNm; this.compTime = compTime; this.compTitle = compTitle; this.toCompName = toCompName; this.toCompDept = toCompDept; this.compContent = compContent; this.state = state; this.complainReplies = complainReplies; } // 下面是get和set方法,这里不再赘述 }
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="cn.edu.hpu.tax.complain.entity.Complain" table="complain"> <id name="compId" type="java.lang.String"> <column name="comp_id" length="32" /> <generator class="uuid.hex" /> </id> <property name="compCompany" type="java.lang.String"> <column name="comp_company" length="100" /> </property> <property name="compName" type="java.lang.String"> <column name="comp_name" length="20" /> </property> <property name="compMobile" type="java.lang.String"> <column name="comp_mobile" length="20" /> </property> <property name="isNm" type="java.lang.Boolean"> <column name="is_NM" /> </property> <property name="compTime" type="java.sql.Timestamp"> <column name="comp_time" length="19" /> </property> <property name="compTitle" type="java.lang.String"> <column name="comp_title" length="200" not-null="true" /> </property> <property name="toCompName" type="java.lang.String"> <column name="to_comp_name" length="20" /> </property> <property name="toCompDept" type="java.lang.String"> <column name="to_comp_dept" length="100" /> </property> <property name="compContent" type="text"> <column name="comp_content"/> </property> <property name="state" type="java.lang.String"> <column name="state" length="1" /> </property> <set name="complainReplies" inverse="true" cascade="save-update,delete" lazy="false" order-by="reply_time"> <key> <column name="comp_id" length="32" not-null="true" /> </key> <one-to-many class="cn.edu.hpu.tax.complain.entity.ComplainReply" /> </set> </class> </hibernate-mapping>
package cn.edu.hpu.tax.complain.entity; import java.sql.Timestamp; /** * ComplainReply entity. @author MyEclipse Persistence Tools */ public class ComplainReply implements java.io.Serializable { // Fields private String replyId; private Complain complain; private String replyer; private String replyDept; private Timestamp replyTime; private String replyContent; // Constructors /** default constructor */ public ComplainReply() { } /** minimal constructor */ public ComplainReply(Complain complain) { this.complain = complain; } /** full constructor */ public ComplainReply(Complain complain, String replyer, String replyDept, Timestamp replyTime, String replyContent) { this.complain = complain; this.replyer = replyer; this.replyDept = replyDept; this.replyTime = replyTime; this.replyContent = replyContent; } // 下面是get和set方法,这里不再赘述 }
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="cn.edu.hpu.tax.complain.entity.ComplainReply" table="complain_reply"> <id name="replyId" type="java.lang.String"> <column name="reply_id" length="32" /> <generator class="uuid.hex" /> </id> <many-to-one name="complain" class="cn.edu.hpu.tax.complain.entity.Complain" fetch="select"> <column name="comp_id" length="32" not-null="true" /> </many-to-one> <property name="replyer" type="java.lang.String"> <column name="replyer" length="20" /> </property> <property name="replyDept" type="java.lang.String"> <column name="reply_dept" length="100" /> </property> <property name="replyTime" type="java.sql.Timestamp"> <column name="reply_time" length="19" /> </property> <property name="replyContent" type="java.lang.String"> <column name="reply_content" length="300" /> </property> </class> </hibernate-mapping>
可以看到我们正确生成了实体集以及映射文件。
//状态 public static String COMPLAIN_STATE_UNDONE = "0";//待受理 public static String COMPLAIN_STATE_DONE = "1";//已受理 public static String COMPLAIN_STATE_INVALID = "2";//已失效 public static Map<String, String> COMPLAIN_STATE_MAP; static { COMPLAIN_STATE_MAP = new HashMap<String, String>(); COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_UNDONE, "待受理"); COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_DONE, "已受理"); COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_INVALID, "已失效"); }
package cn.edu.hpu.tax.complain.dao; import cn.edu.hpu.tax.complain.entity.Complain; import cn.edu.hpu.tax.core.dao.BaseDao; public interface ComplainDao extends BaseDao<Complain> { }
package cn.edu.hpu.tax.complain.dao.impl; import cn.edu.hpu.tax.complain.dao.ComplainDao; import cn.edu.hpu.tax.complain.entity.Complain; import cn.edu.hpu.tax.core.dao.impl.BaseDaoImpl; public class ComplainDaoImpl extends BaseDaoImpl<Complain> implements ComplainDao{ }
package cn.edu.hpu.tax.complain.service; import cn.edu.hpu.tax.complain.entity.Complain; import cn.edu.hpu.tax.core.service.BaseService; public interface ComplainService extends BaseService<Complain> { }
package cn.edu.hpu.tax.complain.service.impl; import javax.annotation.Resource; import org.springframework.stereotype.Service; import cn.edu.hpu.tax.complain.dao.ComplainDao; import cn.edu.hpu.tax.complain.entity.Complain; import cn.edu.hpu.tax.complain.service.ComplainService; import cn.edu.hpu.tax.core.service.impl.BaseServiceImpl; @Service("complainService") public class ComplainServiceImpl extends BaseServiceImpl<Complain> implements ComplainService { private ComplainDao complainDao; @Resource public void setComplainDao(ComplainDao complainDao) { super.setBaseDao(complainDao); this.complainDao = complainDao; } }
package cn.edu.hpu.tax.complain.action; import javax.annotation.Resource; import cn.edu.hpu.tax.complain.entity.Complain; import cn.edu.hpu.tax.complain.service.ComplainService; import cn.edu.hpu.tax.core.action.BaseAction; import cn.edu.hpu.tax.core.util.QueryHelper; public class ComplainAction extends BaseAction { @Resource private ComplainService complainService; private Complain complain; //列表 public String listUI(){ //加载状态集合 ActionContext.getContext().getContextMap().put("complainStateMap", Complain.COMPLAIN_STATE_MAP); QueryHelper queryHelper=new QueryHelper(Complain.class,"c"); pageResult=complainService.getPageResult(queryHelper, getPageNo(), getPageSize()); return "listUI"; } public Complain getComplain() { return complain; } public void setComplain(Complain complain) { this.complain = complain; } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 继承了注入sessionFactory的抽象类,不用反复出入sessionFactory --> <bean id="complainDao" class="cn.edu.hpu.tax.complain.dao.impl.ComplainDaoImpl" parent="xDao"></bean> <!-- 扫描Service --> <context:component-scan base-package="cn.edu.hpu.tax.complain.service.impl"></context:component-scan> </beans>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="complain-action" namespace="/tax" extends="base-default"> <action name="complain_*" class="cn.edu.hpu.tax.complain.action.ComplainAction" method="{1}"> <result name="{1}">/WEB-INF/jsp/tax/complain/{1}.jsp</result> <result name="list" type="redirectAction"> <param name="actionName">complain_listUI</param> <param name="complain.name">${strTitle}</param> <param name="pageNo">${pageNo}</param> <param name="encode">true</param><!-- 需要编码 --> </result> </action> </package> </struts>
<!-- 投诉受理的struts配置文件 --> <include file="cn/edu/hpu/tax/complain/conf/complain-struts.xml"/>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <%@include file="/common/header.jsp"%> <title>投诉受理管理</title> <script type="text/javascript" src="${basePath }js/datepicker/WdatePicker.js"></script> <script type="text/javascript"> var list_url = "${basePath}tax/complain_listUI.action"; //搜索 function doSearch(){ //重置页号 $("#pageNo").val(1); document.forms[0].action = list_url; document.forms[0].submit(); } //受理 function doDeal(compId){ document.forms[0].action = "${basePath}tax/complain_dealUI.action?complain.compId=" + compId; document.forms[0].submit(); } </script> </head> <body class="rightBody"> <form name="form1" action="" method="post"> <div class="p_d_1"> <div class="p_d_1_1"> <div class="content_info"> <div class="c_crumbs"><div><b></b><strong>投诉受理管理</strong></div> </div> <div class="search_art"> <li> 投诉标题:<s:textfield name="complain.compTitle" cssClass="s_text" cssStyle="width:160px;"/> </li> <li> 投诉时间:<s:textfield id="startTime" name="startTime" cssClass="s_text" cssStyle="width:160px;" readonly="true" onfocus="WdatePicker({'skin':'whyGreen','dateFmt':'yyyy-MM-dd HH:mm'});"/> - <s:textfield id="endTime" name="endTime" cssClass="s_text" cssStyle="width:160px;" readonly="true" onfocus="WdatePicker({'skin':'whyGreen','dateFmt':'yyyy-MM-dd HH:mm'});"/> </li> <li> 状态:<s:select name="complain.state" list="#complainStateMap" headerKey="" headerValue="全部"/> </li> <li><input type="button" class="s_button" value="搜 索" onclick="doSearch()"/></li> <li style="float:right;"> <input type="button" value="统计" class="s_button" onclick="doAnnualStatistic()"/> </li> </div> <div class="t_list" style="margin:0px; border:0px none;"> <table width="100%" border="0"> <tr class="t_tit"> <td align="center">投诉标题</td> <td width="120" align="center">被投诉部门</td> <td width="120" align="center">被投诉人</td> <td width="140" align="center">投诉时间</td> <td width="100" align="center">受理状态</td> <td width="100" align="center">操作</td> </tr> <s:iterator value="pageResult.items" status="st"> <tr <s:if test="#st.odd"> bgcolor="f8f8f8" </s:if> > <td align="center"><s:property value="compTitle"/></td> <td align="center"><s:property value="toCompDept"/></td> <td align="center"><s:property value="toCompName"/></td> <td align="center"><s:date name="compTime" format="yyyy-MM-dd HH:mm"/></td> <td align="center"><s:property value="#complainStateMap[state]"/></td> <td align="center"> <a href="javascript:doDeal('<s:property value='compId'/>')">受理</a> </td> </tr> </s:iterator> </table> </div> </div> <jsp:include page="/common/pageNavigator.jsp"/> </div> </div> </form> </body> </html>
<dl class=""> <dt><a class="tssl" href="${ctx }tax/complain_listUI.action" target="mainFrame"><b></b>投诉受理管理<s lass="down"></s> </a> </dt> </dl>
package cn.edu.hpu.tax.complain.action; import java.net.URLDecoder; import javax.annotation.Resource; import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang3.StringUtils; import cn.edu.hpu.tax.complain.entity.Complain; import cn.edu.hpu.tax.complain.service.ComplainService; import cn.edu.hpu.tax.core.action.BaseAction; import cn.edu.hpu.tax.core.util.QueryHelper; import com.opensymphony.xwork2.ActionContext; public class ComplainAction extends BaseAction { @Resource private ComplainService complainService; private Complain complain; private String startTime; private String endTime; //列表 public String listUI() throws Exception{ //加载状态集合 ActionContext.getContext().getContextMap().put("complainStateMap", Complain.COMPLAIN_STATE_MAP); QueryHelper queryHelper=new QueryHelper(Complain.class,"c"); if(StringUtils.isNoneBlank(startTime)){//查询开始时间之后的投诉数据 startTime=URLDecoder.decode(startTime,"utf-8"); queryHelper.addCondition("c.compTime > ?",DateUtils.parseDate(startTime, new String[]{"yyyy-MM-dd HH:mm"})); } if(StringUtils.isNoneBlank(endTime)){//查询结束时间之前的投诉数据 endTime=URLDecoder.decode(endTime,"utf-8"); queryHelper.addCondition("c.compTime < ?",DateUtils.parseDate(endTime, new String[]{"yyyy-MM-dd HH:mm"})); } if(complain!=null){ if(StringUtils.isNoneBlank(complain.getState())){ queryHelper.addCondition("c.state=?", complain.getState()); } if(StringUtils.isNoneBlank(complain.getCompTitle())){ complain.setCompTitle(URLDecoder.decode(complain.getCompTitle(),"utf-8")); queryHelper.addCondition("c.compTitle like ?", "%"+complain.getCompTitle()+"%"); } } //按照状态升序排序(待受理排前,已受理和过期在后) queryHelper.addOrderByProperty("c.state", QueryHelper.ORDER_BY_ASC); //按照投诉时间升序排序 queryHelper.addOrderByProperty("c.compTime", QueryHelper.ORDER_BY_ASC); pageResult=complainService.getPageResult(queryHelper, getPageNo(), getPageSize()); return "listUI"; } public Complain getComplain() { return complain; } public void setComplain(Complain complain) { this.complain = complain; } public String getStartTime() { return startTime; } public void setStartTime(String startTime) { this.startTime = startTime; } public String getEndTime() { return endTime; } public void setEndTime(String endTime) { this.endTime = endTime; } }
我们的分段多条件查询功能编写成功。下一次我们继续进行功能的完善。
转载请注明出处:http://blog.csdn.net/acmman/article/details/50061537