1、投诉和投诉回复实体及hbm配置文件
Complain.java
package cn.buaa.nsfw.complain.entity;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Complain 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 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);
//状态
//待受理
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, "已失效");
}
// 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;
}
// Property accessors
public String getCompId() {
return this.compId;
}
public void setCompId(String compId) {
this.compId = compId;
}
public String getCompCompany() {
return this.compCompany;
}
public void setCompCompany(String compCompany) {
this.compCompany = compCompany;
}
public String getCompName() {
return this.compName;
}
public void setCompName(String compName) {
this.compName = compName;
}
public String getCompMobile() {
return this.compMobile;
}
public void setCompMobile(String compMobile) {
this.compMobile = compMobile;
}
public Boolean getIsNm() {
return this.isNm;
}
public void setIsNm(Boolean isNm) {
this.isNm = isNm;
}
public Timestamp getCompTime() {
return this.compTime;
}
public void setCompTime(Timestamp compTime) {
this.compTime = compTime;
}
public String getCompTitle() {
return this.compTitle;
}
public void setCompTitle(String compTitle) {
this.compTitle = compTitle;
}
public String getToCompName() {
return this.toCompName;
}
public void setToCompName(String toCompName) {
this.toCompName = toCompName;
}
public String getToCompDept() {
return this.toCompDept;
}
public void setToCompDept(String toCompDept) {
this.toCompDept = toCompDept;
}
public String getCompContent() {
return this.compContent;
}
public void setCompContent(String compContent) {
this.compContent = compContent;
}
public String getState() {
return this.state;
}
public void setState(String state) {
this.state = state;
}
public Set getComplainReplies() {
return this.complainReplies;
}
public void setComplainReplies(Set complainReplies) {
this.complainReplies = complainReplies;
}
}
Complain.hbm.xml
<?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.buaa.nsfw.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.buaa.nsfw.complain.entity.ComplainReply" />
</set>
</class>
</hibernate-mapping>
注意,<set>中有个
order-by="reply_time"属性,可以使set按数据库中某个字段,或者实体中某个属性排序,还可以设置desc 或asc
ComplainReply.java
package cn.buaa.nsfw.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;
}
// Property accessors
public String getReplyId() {
return this.replyId;
}
public void setReplyId(String replyId) {
this.replyId = replyId;
}
public Complain getComplain() {
return this.complain;
}
public void setComplain(Complain complain) {
this.complain = complain;
}
public String getReplyer() {
return this.replyer;
}
public void setReplyer(String replyer) {
this.replyer = replyer;
}
public String getReplyDept() {
return this.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 this.replyContent;
}
public void setReplyContent(String replyContent) {
this.replyContent = replyContent;
}
}
ComplainReply.hbm.xml
<?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.buaa.nsfw.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.buaa.nsfw.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>
2、action中对级联查询的操作
//保存回复处理结果
public String deal(){
if(complain != null){
Complain tem = complainService.findObjectById(complain.getCompId());
//1、更新投诉的状态为已受理
if(!Complain.COMPLAIN_STATE_DONE.equals(tem.getState())){ //更新状态为已受理
tem.setState(Complain.COMPLAIN_STATE_DONE);
}
//2、保存回复信息
if(reply != null){
reply.setComplain(tem);
reply.setReplyTime(new Timestamp(new Date().getTime()));
tem.getComplainReplies().add(reply);
}
complainService.update(tem);
}
return "list";
}
3、jsp页面
<%@ 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 vResult = false;
function doVerify() {
//1.获取账号
var account = $("#account").val();
if (account != "") {
//2.效验
$.ajax({
url : "${basePath}nsfw/user_verifyAccount.action",
data : {
"user.account" : account
},
type : "post",
async : false,//非异步,主要为了下边的提交
success : function(msg) {
if ("true" != msg) {
//账号已经存在
alert("账号已经存在,请使用其他账号!");
//定焦
$("#account").focus();
vResult = false;
} else {
vResult = true;
}
}
});
}
}
//2.提交表单
function doSubmit() {
var name = $("#name");
if (name.val() == "") {
alert("用户名不能为空");
name.focus();
return false;
}
var password = $("#password");
if (password.val() == "") {
alert("密码不能为空");
password.focus();
return false;
}
//账号验证
doVerify();
//表单提交
if (vResult) {
document.forms[0].submit();
}
}
</script>
</head>
<body class="rightBody">
<form id="form" name="form" action="${basePath}nsfw/user_add.action" method="post" enctype="multipart/form-data">
<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="tableH2">新增用户</div>
<table id="baseInfo" width="100%" align="center" class="list" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="tdBg" width="200px">所属部门:</td>
<td>
<s:select name="user.dept" list="#{'部门A':'部门A','部门B':'部门B'}" />
</td>
</tr>
<tr>
<td class="tdBg" width="200px">头像:</td>
<td>
<input type="file" name="headImg" />
</td>
</tr>
<tr>
<td class="tdBg" width="200px">用户名:</td>
<td>
<s:textfield name="user.name" id="name" />
</td>
</tr>
<tr>
<td class="tdBg" width="200px">帐号:</td>
<td>
<s:textfield name="user.account" id="account" οnchange="doVerify()" />
</td>
</tr>
<tr>
<td class="tdBg" width="200px">密码:</td>
<td>
<s:textfield name="user.password" id="password" />
</td>
</tr>
<tr>
<td class="tdBg" width="200px">性别:</td>
<td>
<s:radio list="#{'true':'男','false':'女'}" name="user.gender" />
</td>
</tr>
<tr>
<td class="tdBg" width="200px">角色:</td>
<td>
<s:checkboxlist list="#roleList" name="userRoleIds" listKey="roleId" listValue="name"></s:checkboxlist>
</td>
</tr>
<tr>
<td class="tdBg" width="200px">电子邮箱:</td>
<td>
<s:textfield name="user.email" />
</td>
</tr>
<tr>
<td class="tdBg" width="200px">手机号:</td>
<td>
<s:textfield name="user.mobile" />
</td>
</tr>
<tr>
<td class="tdBg" width="200px">生日:</td>
<td>
<s:textfield id="birthday" name="user.birthday" readonly="true"
οnfοcus="WdatePicker({'skin':'whyGreen','dateFmt':'yyyy-MM-dd'})" />
</td>
</tr>
<tr>
<td class="tdBg" width="200px">状态:</td>
<td>
<s:radio list="#{'1':'有效','0':'无效'}" name="user.state" value="1" />
</td>
</tr>
<tr>
<td class="tdBg" width="200px">备注:</td>
<td>
<s:textarea name="user.memo" cols="75" rows="3" />
</td>
</tr>
</table>
<div class="tc mt20">
<input type="button" class="btnB2" value="保存" οnclick="doSubmit()" />
<input type="button" οnclick="javascript:history.go(-1)" class="btnB2" value="返回" />
</div>
</div>
</div>
</div>
</form>
</body>
</html>