一、基础准备
1.更改staff.jsp页面,删除编号的<input>标签
2.更改staff.hbm.xml配置文件,生成策略为uuid(Hibernate自动生成的长度为32为,没有横线)
二、添加基于easyui的自定义校验规则 - 扩展手机号校验规则
1.自定义扩展规则
$(function(){
//扩展手机号校验规则
$.extend($.fn.validatebox.defaults.rules, {
telephone:{
validator:function(value, param){
var reg = /^1[3|4|5|7|8][0-9]{9}$/;
return reg.test(value);
},
message:"手机号输入有误"
}
});
});
2.手机号的<input>应用自定义规则
<input type="text" data-options="validType:‘telephone‘" name="telephone" class="easyui-validatebox" required="true"/>
三、为保存按钮添加事件
//为保存按钮添加事件
$("#save").click(function(){
//表单校验
var validateRes = $("#addStaffForm").form("validate");
if(validateRes){
//通过则提交表单
$("#addStaffForm").submit();
}
});
死、服务端实现
1.创建StaffAction.add方法
@Controller("staffAction")
@Scope("prototype")
public class StaffAction extends BaseAction<Staff>{
private static final long serialVersionUID = 1L;
/**
* 添加取派员
* @return
*/
public String add(){
staffService.save(model);
return LIST;
}
@Autowired
private StaffService staffService;
public StaffService getStaffService() {
return staffService;
}
public void setStaffService(StaffService staffService) {
this.staffService = staffService;
}
}
2.创建StaffService相关
public interface StaffService {
void save(Staff model);
}
@Service
@Transactional(isolation=Isolation.REPEATABLE_READ, propagation=Propagation.REQUIRED, readOnly=true)
public class StaffServiceImpl implements StaffService{
@Override
@Transactional(isolation=Isolation.REPEATABLE_READ, propagation=Propagation.REQUIRED, readOnly=false)
public void save(Staff model) {
staffDao.save(model);
}
private StaffDao staffDao;
public StaffDao getStaffDao() {
return staffDao;
}
public void setStaffDao(StaffDao staffDao) {
this.staffDao = staffDao;
}
}
3.创建StaffDao相关
public interface StaffDao extends BaseDao<Staff>{
}
public class StaffDaoImpl extends BaseDaoImpl<Staff> implements StaffDao{
}
4.配置StaffAction
<action name="staffAction_*" class="staffAction" method="{1}">
<result name="list">/WEB-INF/pages/base/staff.jsp</result>
</action>