Improve employee management
(1) Remove the password when querying the page
1. Visit the emp.html page of the project created above
Password is exposed
Need to block the display of the password when displaying
2. Set the comment in Emp.java in erp_entity
3. The login password disappears when you visit again
Delete the password column in emp.html and
visit again
(2) Display of gender
Modify the gender column in emp.html and
visit the emp.html page again
(3) Date formatting
1. This display is obviously wrong when querying
2. Format the date and introduce date.js
// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function(fmt)
{
//author: meizz
if(isNaN(this.getDate()))
{
return "";
}
var o = {
"M+" : this.getMonth()+1, //月份
"d+" : this.getDate(), //日
"h+" : this.getHours(), //小时
"m+" : this.getMinutes(), //分
"s+" : this.getSeconds(), //秒
"q+" : Math.floor((this.getMonth()+3)/3), //季度
"S" : this.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt))
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)
if(new RegExp("("+ k +")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
return fmt;
}
3. Introduce the js in emp.html (put the above JS into the corresponding ui file)
(4) Improvement of department name
1. Modify the mapping file in emp.hbm.xml
2. Modify Emp, java entity class
3. Modify the content on the emp.html page (add a formatter to the department)
4. Modify the listByPage method and list method of BaseAction:DisableCircularReferenceDetect禁用循环引用保护
5. Visit emp.html again: Implementation
(5) Employee add form editing
1. Set the size of the edit box in crud.js
2. In emp.html (set the text box for the new button editing)
Change gender to radio button
3. Set the corresponding add function on the add page of emp.html (set the corresponding date format)
<td>出生年月日</td>
<td>
<input name="t.birthday" class="easyui-datebox" editable="false" >
</td>
4. Setting of the department drop-down list (set in emp.html)
Get the department list from the dep corresponding to the foreign key in emp
<td>部门</td><td><input name="t.dep.uuid" class="easyui-combobox" data-options="
url:'dep_list',textField:'name',valueField:'uuid' " >
</td>
5. Set some other properties (add verification)
(1) Set the corresponding (validated attributes) in emp.html
<td>登陆名</td>
<td><input name="t.username" class="easyui-validatebox" data-options="
required:true,missingMessage:'登录名不能为空!' ">
</td>
<td>邮件地址</td>
<td><input name="t.email" class="easyui-validatebox" data-options="
required:true,validType:'email',invalidMessage:'Email格式不正确'">
</td>
(2) Set the corresponding (validated attribute) in crud.js to verify when clicking save.
Errors cannot be submitted
//表单验证的时候当所有字段返回true的时候,该方法使用validatebox(验证框架)插件
var isValid = $('#editForm').form('validate');
if(isValid == false ){
return;
}
var formdata= $('#editForm').serializeJSON();
$.ajax({
url:name+'_'+method+'.action',
data:formdata,
dataType:'json',
type:'post',
success:function(value){
if(value.success){
$('#editWindow').window('close');
$('#grid').datagrid('reload');
}
$.messager.alert('提示',value.message);
}
});
(3) Department is requiredrequired:true
6. Employee search (normal form)
(1) Modify the gender in emp.html
(2) Set the drop-down list of the corresponding department
(3) Set the query conditions according to the department in EmpDao
// 根据部门查询
if (null != emp1.getDep() && null != emp1.getDep().getUuid()) {
dc.add(Restrictions.eq("dep", emp1.getDep()));
}
(4) The condition query is successful
7. Employee search (date of birth) to query information in a specified period
(1) Modify the date in the front-end emp.html
出生年月日:<input name="t1.birthday" class="easyui-datebox" editable="false" >
-> <input name="t2.birthday" class="easyui-datebox" editable="false" >
(2) Modify the conditions in the back-end EmpDap
(3) The query is successful
(6) Department related format processing
1. An error will be reported when you click to modify (there is no login name, real name, gender, and date format error)
Modify the get method in BaseAction. The
page successfully displays various information, but the department does not display it
2. Display department information (modify the mapJson method in BaseAction)
private String mapJson(String jsonString, String prefix) {
Map<String, Object> map = JSON.parseObject(jsonString);
Map<String, Object> newmap = new HashMap();
for (String key : map.keySet()) {
if (map.get(key) instanceof Map) {
// 判断左边的类型是否和右边相同
// key值进行拼接
Map<String, Object> m2 = (Map<String, Object>) map.get(key);//将map.get(key)值强制转换为map
for (String key2 : m2.keySet()) {
newmap.put(prefix + "." + key + "." + key2, m2.get(key2));
}
}else {
newmap.put(prefix + "." + key, map.get(key));
}
}
return JSON.toJSONString(newmap);
}
Running again will automatically select the corresponding department