千家信息网

SSH系列:(26)投诉受理

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,1、Hibernate逆向工程1.1、CDM概念模型这里虽然用了T_Complain,但是不建议这样做,因为后面生成JavaBean类时,会生成TComplain.java类,而不是Complain.
千家信息网最后更新 2025年01月20日SSH系列:(26)投诉受理


1、Hibernate逆向工程


1.1、CDM概念模型

这里虽然用了T_Complain,但是不建议这样做,因为后面生成JavaBean类时,会生成TComplain.java类,而不是Complain.java。


1.2、物理模型

1.3、生成的实体类和Hibernate映射文件

Complain.java

package com.rk.tax.entity;import java.sql.Timestamp;import java.util.HashSet;import java.util.Set;import java.util.Map;import java.util.HashMap;/** * TComplain entity. @author MyEclipse Persistence Tools */public class Complain implements java.io.Serializable {        // Fields        private String compId;        private String compCompany;        private String compName;        private String compMobile;        private Boolean isAnonymous;        private Timestamp compTime;        private String compTitle;        private String toCompName;        private String toCompDept;        private String compContent;        private String state;        private Set complainreplies = new HashSet(0);        //状态        public static String COMPLAIN_STATE_UNDONE = "0";        public static String COMPLAIN_STATE_DONE = "1";        public static String COMPLAIN_STATE_INVALID = "2";        public static Map COMPLAIN_STATE_MAP;        static {                COMPLAIN_STATE_MAP = new HashMap();                COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_UNDONE, "待受理");                COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_DONE, "已受理");                COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_INVALID, "已失效");        }                // Constructors        /** default constructor */        public Complain() {        }        public String getCompId() {                return compId;        }        public void setCompId(String compId) {                this.compId = compId;        }        public String getCompCompany() {                return compCompany;        }        public void setCompCompany(String compCompany) {                this.compCompany = compCompany;        }        public String getCompName() {                return compName;        }        public void setCompName(String compName) {                this.compName = compName;        }        public String getCompMobile() {                return compMobile;        }        public void setCompMobile(String compMobile) {                this.compMobile = compMobile;        }        public Boolean getIsAnonymous() {                return isAnonymous;        }        public void setIsAnonymous(Boolean isAnonymous) {                this.isAnonymous = isAnonymous;        }        public Timestamp getCompTime() {                return compTime;        }        public void setCompTime(Timestamp compTime) {                this.compTime = compTime;        }        public String getCompTitle() {                return compTitle;        }        public void setCompTitle(String compTitle) {                this.compTitle = compTitle;        }        public String getToCompName() {                return toCompName;        }        public void setToCompName(String toCompName) {                this.toCompName = toCompName;        }        public String getToCompDept() {                return toCompDept;        }        public void setToCompDept(String toCompDept) {                this.toCompDept = toCompDept;        }        public String getCompContent() {                return compContent;        }        public void setCompContent(String compContent) {                this.compContent = compContent;        }        public String getState() {                return state;        }        public void setState(String state) {                this.state = state;        }        public Set getComplainreplies() {                return complainreplies;        }        public void setComplainreplies(Set complainreplies) {                this.complainreplies = complainreplies;        }}


知识点(1)

       //状态        public static String COMPLAIN_STATE_UNDONE = "0";        public static String COMPLAIN_STATE_DONE = "1";        public static String COMPLAIN_STATE_INVALID = "2";        public static Map COMPLAIN_STATE_MAP;        static {                COMPLAIN_STATE_MAP = new HashMap();                COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_UNDONE, "待受理");                COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_DONE, "已受理");                COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_INVALID, "已失效");        }


Complain.hbm.xml

注意:在生成的映射文件中去掉 catalog="数据库名称"


                                                                                                                                                                                                                                                                                                                                                                                                            


知识点(1):

                            

知识点(2):

                            

知识点(3):

                            

对应的类字段

      private Boolean isAnonymous;        private Timestamp compTime;        private String compContent;

知识点(4):

                                                                    

其中

lazy="false" cascade="save-update" order-by="reply_time"

lazy="false"表示不使用懒加载,

cascade="save-update"表示级联保存、更新

order-by="reply-time"是指取出的数据按照reply-time排序。注意:reply_time是数据库的列的名称,这里也可以类的字段replyTime,但是类的字段replyTime与数据库的列名reply_time相比,类的字段replyTime可能在某些版本中存在问题,而数据库的列名reply_time更具有通用性

另外,也可以对reply-time进行排序,如使用order-by="reply-time desc",它的默认值是asc,可以省略


Complainreply.java

package com.rk.tax.entity;import java.sql.Timestamp;/** * TComplainreply 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;        }        public String getReplyId() {                return replyId;        }        public void setReplyId(String replyId) {                this.replyId = replyId;        }        public Complain getComplain() {                return complain;        }        public void setComplain(Complain complain) {                this.complain = complain;        }        public String getReplyer() {                return replyer;        }        public void setReplyer(String replyer) {                this.replyer = replyer;        }        public String getReplyDept() {                return replyDept;        }        public void setReplyDept(String replyDept) {                this.replyDept = replyDept;        }        public Timestamp getReplyTime() {                return replyTime;        }        public void setReplyTime(Timestamp replyTime) {                this.replyTime = replyTime;        }        public String getReplyContent() {                return replyContent;        }        public void setReplyContent(String replyContent) {                this.replyContent = replyContent;        }}


Complainreply.hbm.xml

注意:在生成的映射文件中去掉 catalog="数据库名称"

                                                                                                                                                                                            



2、从dao到action

dao->service->action->config

2.1、dao层

ComplainDao.java

package com.rk.tax.dao;import com.rk.core.dao.BaseDao;import com.rk.tax.entity.Complain;public interface ComplainDao extends BaseDao {}

ComplainDaoImpl.java

package com.rk.tax.dao.impl;import com.rk.core.dao.impl.BaseDaoImpl;import com.rk.tax.dao.ComplainDao;import com.rk.tax.entity.Complain;public class ComplainDaoImpl extends BaseDaoImpl implements ComplainDao {}


2.2、service层

ComplainService.java

package com.rk.tax.service;import com.rk.core.service.BaseService;import com.rk.tax.entity.Complain;public interface ComplainService extends BaseService {        }

ComplainServiceImpl.java

package com.rk.tax.service.impl;import java.util.Calendar;import java.util.List;import javax.annotation.Resource;import org.springframework.stereotype.Service;import com.rk.core.service.Impl.BaseServiceImpl;import com.rk.core.utils.QueryHelper;import com.rk.tax.dao.ComplainDao;import com.rk.tax.entity.Complain;import com.rk.tax.service.ComplainService;@Service("complainService")public class ComplainServiceImpl extends BaseServiceImpl implements ComplainService {        private ComplainDao complainDao;        @Resource        public void setComplainDao(ComplainDao complainDao) {                setBaseDao(complainDao);                this.complainDao = complainDao;        }}



2.3、action层

ComplainAction.java

package com.rk.tax.action;import java.net.URLDecoder;import java.sql.Timestamp;import java.util.Date;import javax.annotation.Resource;import org.apache.commons.lang3.StringUtils;import org.apache.commons.lang3.time.DateUtils;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Controller;import com.opensymphony.xwork2.ActionContext;import com.rk.core.action.BaseAction;import com.rk.core.utils.QueryHelper;import com.rk.tax.entity.Complain;import com.rk.tax.entity.Complainreply;import com.rk.tax.service.ComplainService;@Controller("complainAction")@Scope("prototype")public class ComplainAction extends BaseAction {        /*****1、业务数据*****/        private Complain complain;        private String startTime;        private String endTime;        private String state;        private Complainreply reply;        /*****2、业务实现类*****/        @Resource        private ComplainService complainService;                /*****3、响应页面操作*****/        //列表        public String listUI(){                //加载状态集合                ActionContext.getContext().getContextMap().put("complainStateMap", Complain.COMPLAIN_STATE_MAP);                try {                        QueryHelper queryHelper = new QueryHelper(Complain.class, "c");                        if(StringUtils.isNotBlank(startTime)){//查询开始时间之后的投诉数据                                startTime = URLDecoder.decode(startTime, "utf-8");                                queryHelper.addCondition("c.compTime >= ?", DateUtils.parseDate(startTime+":00", "yyyy-MM-dd HH:mm:ss"));                        }                        if(StringUtils.isNotBlank(endTime)){//查询结束时间之前的投诉数据                                endTime = URLDecoder.decode(endTime, "utf-8");                                queryHelper.addCondition("c.compTime <= ?", DateUtils.parseDate(endTime+":00", "yyyy-MM-dd HH:mm:ss"));                        }                        if(StringUtils.isNotBlank(searchContent)){                                searchContent = URLDecoder.decode(searchContent, "utf-8");                                queryHelper.addCondition("c.compTitle like ?", "%" + searchContent + "%");                        }                        if(StringUtils.isNotBlank(state)){                                queryHelper.addCondition("c.state=?", state);                        }                        //按照状态升序排序                        queryHelper.addOrderByProperty("c.state", QueryHelper.ORDER_BY_ASC);                        //按照投诉时间升序排序                        queryHelper.addOrderByProperty("c.compTime", QueryHelper.ORDER_BY_ASC);                        pageResult = complainService.getPageResult(queryHelper, pageNo, pageSize);                } catch (Exception e) {                        e.printStackTrace();                }                return "listUI";        }                //跳转到受理页面        public String dealUI(){                //加载状态集合                ActionContext.getContext().getContextMap().put("complainStateMap", Complain.COMPLAIN_STATE_MAP);                if(complain != null && StringUtils.isNotBlank(complain.getCompId())){                        complain = complainService.findById(complain.getCompId());                }                return "dealUI";        }                public String deal(){                if(complain != null && StringUtils.isNotBlank(complain.getCompId())){                        Complain temp = complainService.findById(complain.getCompId());                        //1、更新投诉的状态为 已受理                        if(!Complain.COMPLAIN_STATE_DONE.equals(temp.getState())){                                temp.setState(Complain.COMPLAIN_STATE_DONE);                        }                        //2、保存回复信息                        if(reply != null){                                reply.setComplain(temp);                                /**                                 * 在后台设置时间,有两点好处:                                 * (1)在前台JSP页面,不需要再提供相应的表单域                                 * (2)有两个时间:JSP前台页面生成的时间、服务器保存数据的时间,后者更准确一些                                 */                                reply.setReplyTime(new Timestamp(new Date().getTime()));                                 temp.getComplainreplies().add(reply);                        }                        complainService.update(temp);                }                return "list";        }                // Properties        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;        }        public String getState() {                return state;        }        public void setState(String state) {                this.state = state;        }        public Complainreply getReply() {                return reply;        }        public void setReply(Complainreply reply) {                this.reply = reply;        }}


知识点(1):级联 保存、更新

在deal()方法中

                      Complain temp = complainService.findById(complain.getCompId());                        //1、更新投诉的状态为 已受理                        if(!Complain.COMPLAIN_STATE_DONE.equals(temp.getState())){                                temp.setState(Complain.COMPLAIN_STATE_DONE);                        }                        //2、保存回复信息                        if(reply != null){                                reply.setComplain(temp);                                /**                                 * 在后台设置时间,有两点好处:                                 * (1)在前台JSP页面,不需要再提供相应的表单域                                 * (2)有两个时间:JSP前台页面生成的时间、服务器保存数据的时间,后者更准确一些                                 */                                reply.setReplyTime(new Timestamp(new Date().getTime()));                                 temp.getComplainreplies().add(reply);                        }                        complainService.update(temp);

最后只调用complainService.update(temp),而temp是Complain类型的变量,而真正想要保存的的reply变量,这是通过级联保存(更新)实现的,Complain.hbm.xml中设置了cascade="save-update"

                                                                    


2.4、config

entity层的配置就是*.hbm.xml文件

dao层的配置是将dao类加入到Spring的IOC容器中

service层的配置是将service类加入到Spring的IOC容器中

action层的配置是将action类加入到Spring的IOC容器中,并在struts中对action进行url映射

最后记得将spring和struts的配置都汇总到applicationContext.xml和struts.xml文件中


3、JSP页面


listUI.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>    <%@include file="/common/header.jsp"%>    投诉受理管理        
<%@include file="/common/pageNavigator.jsp" %>

知识点(1):WDatePicker

知识点(2)


dealUI.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>    <%@include file="/common/header.jsp"%>    投诉受理管理

知识点(1):OGNL字符中长度判断 和 拼接

        

知识点(2)

知识点(3) 似乎对OGNL的支持不同

知识点(4):escape

投诉内容:











0