一步一步做项目(12)扩展(增加用户管理的属性)
在前面一步一步做项目(7)管理用户信息之Web页面构建的基础上继续。
由于前面已经建立了整个系统的框架,各部分构件也便于修改和扩展,这里就给大家展示如何扩展。这里主要介绍如何添加新的数据属性,也就是添加新的数据项,在前面框架搭建的基础上,你会发现这仍然是很容易的事。
添加实体类属性
这里,要想添加新的属性,需要在实体类中进行扩充,例如,我现在在Users.java类中添加几个属性,如下所示:
// 创建人
private String userCreator;
// 创建时间
private Date userCreatingTime;
// 审核人
private String userAuditor;
// 审核时间
private Date userAuditingTime;
这里的几个属性,通常对于User类来说,没有多大意义,即使对大多数类来说,也没有多大意义,但是对内容来说,通常可以提供更多的扩展和管理,可以存储这些相关的信息,一般是作为隐藏属性由代码自动添加的,作为模板,我现在在这里加上,之后,产生对应的getter和setter方法即可。
请注意的是,这里的Date数据类型,对于不同于String类型的Date类型,是你在处理时经常出错的原因,之所以这么做,是为了练习Date类型数据的处理。
下面要介绍的是,如何处理用户类型,用户分成不同的种类,你可以定义一个Role类,和User类相关联,也可以简单的定义一个状态类和其相关联,这里,只是简单的定义了一个UserStatus类,关于UserStatus.java类的代码如下:
package cn.lut.curiezhang.model;
import java.util.ResourceBundle;
public enum UserStatus {
// 用户状态:0学生 1院校 2考点 3管理员 4锁定学生 5锁定院校 6锁定考点 7锁定管理员 8找回学生密码 9找回院校密码 10找回考点密码 11找回管理员密码
STUDENT(Byte.valueOf("0"), ResourceBundle.getBundle("Messages").getString("Users.status." + 0)),
COLLEGE(Byte.valueOf("1"), ResourceBundle.getBundle("Messages").getString("Users.status." + 1)),
SITE(Byte.valueOf("2"), ResourceBundle.getBundle("Messages").getString("Users.status." + 2)),
ADMINISTRATOR(Byte.valueOf("3"), ResourceBundle.getBundle("Messages").getString("Users.status." + 3)),
LOCK_STUDENT(Byte.valueOf("10"), ResourceBundle.getBundle("Messages").getString("Users.status." + 10)),
LOCK_COLLEGE(Byte.valueOf("11"), ResourceBundle.getBundle("Messages").getString("Users.status." + 11)),
LOCK_SITE(Byte.valueOf("12"), ResourceBundle.getBundle("Messages").getString("Users.status." + 12)),
LOCK_ADMINISTRATOR(Byte.valueOf("13"), ResourceBundle.getBundle("Messages").getString("Users.status." + 13)),
FIND_PASSWORD_STUDENT(Byte.valueOf("90"), ResourceBundle.getBundle("Messages").getString("Users.status." + 90)),
FIND_PASSWORD_COLLEGE(Byte.valueOf("91"), ResourceBundle.getBundle("Messages").getString("Users.status." + 91)),
FIND_PASSWORD_SITE(Byte.valueOf("92"), ResourceBundle.getBundle("Messages").getString("Users.status." + 92)),
FIND_PASSWORD_ADMINISTRATOR(Byte.valueOf("93"), ResourceBundle.getBundle("Messages").getString("Users.status." + 93));
private Byte index;
private String information;
public Byte getIndex() {
return index;
}
public void setIndex(Byte index) {
this.index = index;
}
public String getInformation() {
return information;
}
public void setInformation(String information) {
this.information = information;
}
private UserStatus(Byte index, String information) {
this.index = index;
this.information = information;
}
private UserStatus(Byte index) {
this.index = index;
}
}
这里,定义了一个enum——枚举类,之所以这么做,一来是因为系统不是很复杂,各类用户职责明确,不需要复杂的用户权限管理,二来纯粹是练习枚举类在Hibernate中的应用。
那么,就将UserStatus属性添加到Users.java类中,现在需要添加下面的代码:
// 创建人
private String userCreator;
// 创建时间
private Date userCreatingTime;
// 审核人
private String userAuditor;
// 审核时间
private Date userAuditingTime;
// 用户状态:0学生 1院校 2考点 3管理员 4锁定学生 5锁定院校 6锁定考点 7锁定管理员 8找回学生密码 9找回院校密码 10找回考点密码 11找回管理员密码
private UserStatus status;
@SuppressWarnings("unused")
private String statusView;
public String getUserCreator() {
return userCreator;
}
public void setUserCreator(String userCreator) {
this.userCreator = userCreator;
}
public Date getUserCreatingTime() {
return userCreatingTime;
}
public void setUserCreatingTime(Date userCreatingTime) {
this.userCreatingTime = userCreatingTime;
}
public String getUserAuditor() {
return userAuditor;
}
public void setUserAuditor(String userAuditor) {
this.userAuditor = userAuditor;
}
public Date getUserAuditingTime() {
return userAuditingTime;
}
public void setUserAuditingTime(Date userAuditingTime) {
this.userAuditingTime = userAuditingTime;
}
public UserStatus getStatus() {
return status;
}
public void setStatus(UserStatus status) {
this.status = status;
}
public String getStatusView() {
if (this.status == null) {
return ResourceBundle.getBundle("Messages").getString("Application.null");
} else if (status == UserStatus.STUDENT) {
return ResourceBundle.getBundle("Messages").getString("Users.status.STUDENT");
} else if (status == UserStatus.COLLEGE) {
return ResourceBundle.getBundle("Messages").getString("Users.status.COLLEGE");
} else if (status == UserStatus.SITE) {
return ResourceBundle.getBundle("Messages").getString("Users.status.SITE");
} else if (status == UserStatus.ADMINISTRATOR) {
return ResourceBundle.getBundle("Messages").getString("Users.status.ADMINISTRATOR");
} else if (status == UserStatus.LOCK_STUDENT) {
return ResourceBundle.getBundle("Messages").getString("Users.status.LOCK_STUDENT");
} else if (status == UserStatus.LOCK_COLLEGE) {
return ResourceBundle.getBundle("Messages").getString("Users.status.LOCK_COLLEGE");
} else if (status == UserStatus.LOCK_SITE) {
return ResourceBundle.getBundle("Messages").getString("Users.status.LOCK_SITE");
} else if (status == UserStatus.LOCK_ADMINISTRATOR) {
return ResourceBundle.getBundle("Messages").getString("Users.status.LOCK_ADMINISTRATOR");
} else if (status == UserStatus.FIND_PASSWORD_STUDENT) {
return ResourceBundle.getBundle("Messages").getString("Users.status.FIND_PASSWORD_STUDENT");
} else if (status == UserStatus.FIND_PASSWORD_COLLEGE) {
return ResourceBundle.getBundle("Messages").getString("Users.status.FIND_PASSWORD_COLLEGE");
} else if (status == UserStatus.FIND_PASSWORD_SITE) {
return ResourceBundle.getBundle("Messages").getString("Users.status.FIND_PASSWORD_SITE");
} else if (status == UserStatus.FIND_PASSWORD_ADMINISTRATOR) {
return ResourceBundle.getBundle("Messages").getString("Users.status.FIND_PASSWORD_ADMINISTRATOR");
} else {
return "";
}
}
public void setStatusView(String statusView) {
this.statusView = statusView;
}
请注意,这里的statusView属性是不存储到数据库中的,数据库里只存储一个简单的数字,这里的statusView纯粹是为了显示的需要。
现在,还需要在Messages.properties中,添加上面代码中用到的属性值,代码如下:
Application.null=NULL
#################### cmis.admin.userStatus ######################
# Users status
Users.status.0=\u8003\u751F
Users.status.1=\u9662\u6821
Users.status.2=\u8003\u70B9
Users.status.3=\u7BA1\u7406\u5458
Users.status.10=\u8003\u751F\u9501\u5B9A
Users.status.11=\u9662\u6821\u9501\u5B9A
Users.status.12=\u8003\u70B9\u9501\u5B9A
Users.status.13=\u7BA1\u7406\u5458\u9501\u5B9A
Users.status.90=\u627E\u56DE\u8003\u751F\u5BC6\u7801
Users.status.91=\u627E\u56DE\u9662\u6821\u5BC6\u7801
Users.status.92=\u627E\u56DE\u8003\u70B9\u5BC6\u7801
Users.status.93=\u627E\u56DE\u7BA1\u7406\u5458\u5BC6\u7801
Users.status.STUDENT=\u8003\u751F
Users.status.COLLEGE=\u9662\u6821
Users.status.SITE=\u8003\u70B9
Users.status.ADMINISTRATOR=\u7BA1\u7406\u5458
Users.status.LOCK_STUDENT=\u8003\u751F\u9501\u5B9A
Users.status.LOCK_COLLEGE=\u9662\u6821\u9501\u5B9A
Users.status.LOCK_SITE=\u8003\u70B9\u9501\u5B9A
Users.status.LOCK_ADMINISTRATOR=\u7BA1\u7406\u5458\u9501\u5B9A
Users.status.FIND_PASSWORD_STUDENT=\u627E\u56DE\u8003\u751F\u5BC6\u7801
Users.status.FIND_PASSWORD_COLLEGE=\u627E\u56DE\u9662\u6821\u5BC6\u7801
Users.status.FIND_PASSWORD_SITE=\u627E\u56DE\u8003\u70B9\u5BC6\u7801
Users.status.FIND_PASSWORD_ADMINISTRATOR=\u627E\u56DE\u7BA1\u7406\u5458\u5BC6\u7801
#################### /cmis.admin.userStatus ######################
完成了java类的扩充,需要扩充Hibernate映射,要修改Users.hbm.xml文件,添加前面扩充的属性的映射,代码如下:
<property name="userCreator">
<column name="USER_CREATOR" length="32">
<comment>创建人</comment>
</column>
</property>
<property name="userCreatingTime" type="java.util.Date">
<column name="USER_CREATING_TIME">
<comment>创建时间</comment>
</column>
</property>
<property name="userAuditor">
<column name="USER_AUDITOR" length="32">
<comment>审核人</comment>
</column>
</property>
<property name="userAuditingTime" type="java.util.Date">
<column name="USER_AUDITING_TIME">
<comment>审核时间</comment>
</column>
</property>
<!-- 0学生 1院校 2考点 3管理员 10锁定学生 11锁定院校 12锁定考点 13锁定管理员 90~93找回密码 -->
<property name="status">
<column name="STATUS" default="0" length="2">
<comment>用户状态:0学生 1院校 2考点 3管理员 4锁定学生 5锁定院校 6锁定考点 7锁定管理员 8找回学生密码 9找回院校密码 10找回考点密码 11找回管理员密码</comment>
</column>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">cn.lut.curiezhang.model.UserStatus</param>
<param name="type">-6</param>
<!-- <param name="useNamed">true</param> -->
</type>
</property>
其它的类不需要处理,现在,就可以重新部署了,要正确执行,需要先删除数据库中原来的users表,因为这里的扩展影响到了原来的表,使原来的表不能添加新的列属性,所以,直接删除重建就可以了,如下图所示。
Web页面处理新的属性
首先,在Messages.properties中,添加Web页面用到的属性值,如下所示:
Users.fieldPrompt.userCreator=\u8BF7\u8F93\u5165\u521B\u5EFA\u4EBA
Users.fieldPrompt.userCreatingTime=\u8BF7\u8F93\u5165\u521B\u5EFA\u65F6\u95F4
Users.fieldPrompt.userAuditor=\u8BF7\u8F93\u5165\u5BA1\u6838\u4EBA
Users.fieldPrompt.userAuditingTime=\u8BF7\u8F93\u5165\u5BA1\u6838\u65F6\u95F4
Users.fieldPrompt.status=\u8BF7\u6307\u5B9A\u7528\u6237\u7C7B\u578B
# Users field name
Users.fieldName.userCreator=\u521B\u5EFA\u4EBA
Users.fieldName.userCreatingTime=\u521B\u5EFA\u65F6\u95F4
Users.fieldName.userAuditor=\u5BA1\u6838\u4EBA
Users.fieldName.userAuditingTime=\u5BA1\u6838\u65F6\u95F4
Users.fieldName.status=\u7528\u6237\u7C7B\u578B
现在,修改index.jsp页面,添加用户类型列,添加的代码如下:
<th><s:text name="Users.fieldName.status"/></th>
<th width="300px"><s:text name="DataTables.title.operate"/></th>
</tr>
</thead>
<tfoot>
<tr>
<th><s:text name="Users.fieldName.userId"/></th>
<th><s:text name="Users.fieldName.userName"/></th>
<th><s:text name="Users.fieldName.userPassword"/></th>
<th><s:text name="Users.fieldName.userPhone"/></th>
<th><s:text name="Users.fieldName.status"/></th>
<th width="300px"><s:text name="DataTables.title.operate"/></th>
</tr>
</tfoot>
<tbody><s:iterator value="model">
<tr>
<td class="verticalMiddle">${userId}</td>
<td class="verticalMiddle"><s:property value="userName"/></td>
<td class="verticalMiddle"><s:property value="userPassword"/></td>
<td class="verticalMiddle"><s:property value="userPhone"/></td>
<td class="verticalMiddle"><s:property value="status.information"/></td>
这里,添加的代码主要是第1行和最后1行,是和用户类型相关的。结果如下图所示:
接着,来修改add.jsp,在页面中添加前面新加入的用户属性,代码如下:
<!-- userCreator -->
<div class="form-group hidden">
<label class="col-sm-6 control-label" for="userCreator">
<s:text name="Users.fieldName.userCreator"/>
</label>
<div class="col-sm-6">
<s:textfield id="userCreator" name="userCreator" value=""
placeholder="%{getText('Users.fieldPrompt.userCreator')}" class="form-control"/>
</div>
<div class="col-sm-6">
<s:fielderror fieldName="userCreator" />
</div>
</div>
<!-- /userCreator -->
<!-- userCreatingTime -->
<div class="form-group hidden">
<label class="col-sm-6 control-label" for="userCreatingTime">
<s:text name="Users.fieldName.userCreatingTime"/>
</label>
<div class="col-sm-6">
<div class="input-group date" id='datetimepicker1'>
<s:textfield id="userCreatingTime" name="userCreatingTime"
placeholder="%{getText('Users.fieldPrompt.userCreatingTime')}" cssClass="form-control"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<%-- <s:textfield id="userCreatingTime" name="userCreatingTime" value=""
placeholder="%{getText('Users.fieldPrompt.userCreatingTime')}" class="form-control"/> --%>
</div>
<div class="col-sm-6">
<s:fielderror fieldName="userCreatingTime" />
</div>
</div>
<!-- /userCreatingTime -->
<script>
$(function () {
$('#datetimepicker1').datetimepicker({
fontAwesome:'font-awesome',
//format: 'YYYY-MM-DD',
language: 'zh-CN'
});
});
</script>
<!-- userAuditor -->
<div class="form-group hidden">
<label class="col-sm-6 control-label" for="userAuditor">
<s:text name="Users.fieldName.userAuditor"/>
</label>
<div class="col-sm-6">
<s:textfield id="userAuditor" name="userAuditor"
placeholder="%{getText('Users.fieldPrompt.userAuditor')}" cssClass="form-control"/>
</div>
<div class="col-sm-6">
<s:fielderror fieldName="userAuditor" />
</div>
</div>
<!-- /userAuditor -->
<!-- userAuditingTime -->
<div class="form-group hidden">
<label class="col-sm-6 control-label" for="userAuditingTime">
<s:text name="Users.fieldName.userAuditingTime"/>
</label>
<div class="col-sm-6">
<div class="input-group date" id='datetimepicker2'>
<s:textfield id="userAuditingTime" name="userAuditingTime"
placeholder="%{getText('Users.fieldPrompt.userAuditingTime')}" cssClass="form-control"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<%-- <s:textfield id="userAuditingTime" name="userAuditingTime"
placeholder="%{getText('Users.fieldPrompt.userAuditingTime')}" cssClass="form-control"/> --%>
</div>
<div class="col-sm-6">
<s:fielderror fieldName="userAuditingTime" />
</div>
</div>
<!-- /userAuditingTime -->
<script>
$(function () {
$('#datetimepicker2').datetimepicker({
fontAwesome:'font-awesome',
//format: 'YYYY-MM-DD',
language: 'zh-CN'
});
});
</script>
<!-- status -->
<div class="form-group">
<label class="col-sm-6 control-label text-danger" for="status">
<s:text name="Users.fieldName.status"/> <i class="fa fa-arrow-circle-right text-danger"></i>
</label>
<div class="col-sm-6">
<select data-placeholder="%{getText('Users.fieldPrompt.status')}"
id="status" name="status" class="selectpicker show-tick" data-width="100%" data-container="body">
<option value="STUDENT" selected><s:text name="Users.status.STUDENT"/></option>
<option value="COLLEGE"><s:text name="Users.status.COLLEGE"/></option>
<option value="SITE"><s:text name="Users.status.SITE"/></option>
<option value="ADMINISTRATOR"><s:text name="Users.status.ADMINISTRATOR"/></option>
<option value="LOCK_STUDENT"><s:text name="Users.status.LOCK_STUDENT"/></option>
<option value="LOCK_COLLEGE"><s:text name="Users.status.LOCK_COLLEGE"/></option>
<option value="LOCK_SITE"><s:text name="Users.status.LOCK_SITE"/></option>
<option value="LOCK_ADMINISTRATOR"><s:text name="Users.status.LOCK_ADMINISTRATOR"/></option>
<option value="FIND_PASSWORD_STUDENT"><s:text name="Users.status.FIND_PASSWORD_STUDENT"/></option>
<option value="FIND_PASSWORD_COLLEGE"><s:text name="Users.status.FIND_PASSWORD_COLLEGE"/></option>
<option value="FIND_PASSWORD_SITE"><s:text name="Users.status.FIND_PASSWORD_SITE"/></option>
<option value="FIND_PASSWORD_ADMINISTRATOR"><s:text name="Users.status.FIND_PASSWORD_ADMINISTRATOR"/></option>
</select>
</div>
<div class="col-sm-6 control-label">
<s:fielderror fieldName="status" />
</div>
</div>
<!-- /status -->
这是新增的部分,添加到块中即可。系统运行截图如下所示:
这里显示的日历,不太理想,这是所用版本的问题,而且在有些js框架中,都可以处理日历的问题,使用时换成合适的日历处理即可。
添加browse.jsp的新增属性处理,如下所示:
<!-- userCreator -->
<tr class="hidden">
<td class="span3 verticalMiddle text-right" width="120px">
<s:text name="Users.fieldName.userCreator"/>
</td>
<td class="span9 verticalMiddle"><s:property value="model.userCreator"/></td>
</tr>
<!-- /userCreator -->
<!-- userCreatingTime -->
<tr class="hidden">
<td class="span3 verticalMiddle text-right" width="120px">
<s:text name="Users.fieldName.userCreatingTime"/>
</td>
<td class="span9 verticalMiddle"><s:date name="model.userCreatingTime" format="yyyy年MM月dd日"/></td>
</tr>
<!-- /userCreatingTime -->
<!-- userAuditor -->
<tr class="hidden">
<td class="span3 verticalMiddle text-right" width="120px">
<s:text name="Users.fieldName.userAuditor"/>
</td>
<td class="span9 verticalMiddle"><s:property value="model.userAuditor"/></td>
</tr>
<!-- /userAuditor -->
<!-- userAuditingTime -->
<tr class="hidden">
<td class="span3 verticalMiddle text-right" width="120px">
<s:text name="Users.fieldName.userAuditingTime"/>
</td>
<td class="span9 verticalMiddle"><s:date name="model.userAuditingTime" format="yyyy年MM月dd日"/></td>
</tr>
<!-- /userAuditingTime -->
<!-- status -->
<tr>
<td class="span3 verticalMiddle text-right"><s:text name="Users.fieldName.status"/></td>
<td class="span9 verticalMiddle"><s:property value="model.status.information"/></td>
</tr>
<!-- /status -->
结果如下图所示:
同样,需要处理modify.jsp,添加的代码如下:
<!-- userCreator -->
<div class="form-group hidden">
<label class="col-sm-6 control-label" for="userCreator">
<s:text name="Users.fieldName.userCreator"/> <i class="fa fa-user text-danger"></i>
</label>
<div class="col-sm-6">
<s:if test="model.userCreator != null">
<s:textfield id="userCreator" name="model.userCreator" value=""
placeholder="%{getText('Users.fieldPrompt.userCreator')}" class="form-control"/>
</s:if>
<s:else>
<s:textfield id="userCreator" name="userCreator" value=""
placeholder="%{getText('Users.fieldPrompt.userCreator')}" class="form-control"/>
</s:else>
</div>
<div class="col-sm-6">
<s:fielderror fieldName="userCreator" />
</div>
</div>
<!-- /userCreator -->
<!-- userCreatingTime -->
<div class="form-group hidden">
<label class="col-sm-6 control-label" for="userCreatingTime">
<s:text name="Users.fieldName.userCreatingTime"/> <i class="fa fa-calendar text-danger"></i>
</label>
<div class="col-sm-6">
<div class="input-group date" id='datetimepicker1'>
<s:if test="model.userCreatingTime != null">
<s:textfield id="userCreatingTime" name="model.userCreatingTime"
placeholder="%{getText('Users.fieldPrompt.userCreatingTime')}" cssClass="form-control"/>
</s:if>
<s:else>
<s:textfield id="userCreatingTime" name="userCreatingTime"
placeholder="%{getText('Users.fieldPrompt.userCreatingTime')}" cssClass="form-control"/>
</s:else>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<%-- <s:textfield id="userCreatingTime" name="userCreatingTime" value=""
placeholder="%{getText('Users.fieldPrompt.userCreatingTime')}" class="form-control"/> --%>
</div>
<div class="col-sm-6">
<s:fielderror fieldName="userCreatingTime" />
</div>
</div>
<!-- /userCreatingTime -->
<script>
$(function () {
$('#datetimepicker1').datetimepicker({
fontAwesome:'font-awesome',
//format: 'YYYY-MM-DD',
language: 'zh-CN'
});
});
</script>
<!-- userAuditor -->
<div class="form-group hidden">
<label class="col-sm-6 control-label" for="userAuditor">
<s:text name="Users.fieldName.userAuditor"/> <i class="fa fa-user text-danger"></i>
</label>
<div class="col-sm-6">
<s:if test="model.userAuditor != null">
<s:textfield id="userAuditor" name="model.userAuditor"
placeholder="%{getText('Users.fieldPrompt.userAuditor')}" cssClass="form-control"/>
</s:if>
<s:else>
<s:textfield id="userAuditor" name="userAuditor"
placeholder="%{getText('Users.fieldPrompt.userAuditor')}" cssClass="form-control"/>
</s:else>
</div>
<div class="col-sm-6">
<s:fielderror fieldName="userAuditor" />
</div>
</div>
<!-- /userAuditor -->
<!-- userAuditingTime -->
<div class="form-group hidden">
<label class="col-sm-6 control-label" for="userAuditingTime">
<s:text name="Users.fieldName.userAuditingTime"/> <i class="fa fa-calendar text-danger"></i>
</label>
<div class="col-sm-6">
<div class="input-group date" id='datetimepicker2'>
<s:if test="model.userAuditingTime != null">
<s:textfield id="userAuditingTime" name="model.userAuditingTime"
placeholder="%{getText('Users.fieldPrompt.userAuditingTime')}" cssClass="form-control"/>
</s:if>
<s:else>
<s:textfield id="userAuditingTime" name="userAuditingTime"
placeholder="%{getText('Users.fieldPrompt.userAuditingTime')}" cssClass="form-control"/>
</s:else>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<%-- <s:textfield id="userAuditingTime" name="userAuditingTime"
placeholder="%{getText('Users.fieldPrompt.userAuditingTime')}" cssClass="form-control"/> --%>
</div>
<div class="col-sm-6">
<s:fielderror fieldName="userAuditingTime" />
</div>
</div>
<!-- /userAuditingTime -->
<script>
$(function () {
$('#datetimepicker2').datetimepicker({
fontAwesome:'font-awesome',
//format: 'YYYY-MM-DD',
language: 'zh-CN'
});
});
</script>
<!-- status -->
<div class="form-group">
<label class="col-sm-6 control-label text-danger" for="status">
<s:text name="Users.fieldName.status"/> <i class="fa fa-arrow-circle-right text-danger"></i>
</label>
<div class="col-sm-6">
<s:textfield id="status" name="model.status" cssClass="form-control d-none" />
<select data-placeholder="%{getText('Users.fieldPrompt.status')}"
id="statusSelect" name="model.status" class="selectpicker show-tick" data-width="100%" data-container="body">
<option value="STUDENT"><s:text name="Users.status.STUDENT"/></option>
<option value="COLLEGE"><s:text name="Users.status.COLLEGE"/></option>
<option value="SITE"><s:text name="Users.status.SITE"/></option>
<option value="ADMINISTRATOR"><s:text name="Users.status.ADMINISTRATOR"/></option>
<option value="LOCK_STUDENT"><s:text name="Users.status.LOCK_STUDENT"/></option>
<option value="LOCK_COLLEGE"><s:text name="Users.status.LOCK_COLLEGE"/></option>
<option value="LOCK_SITE"><s:text name="Users.status.LOCK_SITE"/></option>
<option value="LOCK_ADMINISTRATOR"><s:text name="Users.status.LOCK_ADMINISTRATOR"/></option>
<option value="FIND_PASSWORD_STUDENT"><s:text name="Users.status.FIND_PASSWORD_STUDENT"/></option>
<option value="FIND_PASSWORD_COLLEGE"><s:text name="Users.status.FIND_PASSWORD_COLLEGE"/></option>
<option value="FIND_PASSWORD_SITE"><s:text name="Users.status.FIND_PASSWORD_SITE"/></option>
<option value="FIND_PASSWORD_ADMINISTRATOR"><s:text name="Users.status.FIND_PASSWORD_ADMINISTRATOR"/></option>
</select>
<script type="text/javascript">
$("#statusSelect").val($("#status").val());
$(document).ready(function () {
$("#statusSelect").change(function () {
$("#status").val($("#statusSelect ").val());
});
});
</script>
</div>
<div class="col-sm-6 control-label">
<s:fielderror fieldName="status" />
</div>
</div>
<!-- /status -->
运行结果如下图所示:
至此,修改已经完成,删除不需要修改。
当然,这里的修改还是存在问题,主要是日历控件的使用问题,你在使用的过程中需要注意。
转载:https://blog.csdn.net/ZhangCurie/article/details/102474121