@RequestMapping(value="/student",method=RequestMethod.GET)
public ModelAndView toAddPage(){
ModelAndView mView=new ModelAndView();
mView.addObject("employee",new Employee());
mView.setViewName("add-stu");
mView.addObject("departments", departmentDao.getDepartments());
return mView;
}
@RequestMapping(value="/student",method=RequestMethod.POST)
public String addStu(Employee employee){
employeeDao.save(employee);
return "redirect:/show" ;
}
@RequestMapping(value="/student/{id}",method=RequestMethod.DELETE)
public String deleteStu(@PathVariable(value="id") Integer id){
employeeDao.delete(id);
return "redirect:/show" ;
}
@RequestMapping(value="/student",method=RequestMethod.PUT)
public String Update(@RequestParam(value="id")Integer id,Employee employee){
employeeDao.save(employee);
return "redirect:/show" ;
}
<!-- HiddenHttpMethodFilter过滤器可以将POST请求转化为put请求和delete请求! --> <filter> <filter-name>hiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>hiddenHttpMethodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<form action="" method="post"> <input type="hidden" name="_method" value="delete"> </form>
<form:form action="${pageContext.request.contextPath}/student" method="post" modelAttribute="employee">
<c:if test="${empty employee.id }">
姓名:<form:input path="lastName"/><br>
</c:if>
<c:if test="${!empty employee.id }">
姓名:<form:input path="lastName" readonly="true"/><br>
<form:hidden path="id"/>
<input type="hidden" name="_method" value="put">
</c:if>
邮箱:<form:input path="email"/><br>
<%
Map<String,Object>map=new HashMap<String,Object>();
map.put("1","Male");
map.put("0", "Female");
request.setAttribute("genders", map);
%>
性别:<form:radiobuttons path="gender" items="${genders}"/><br>
部门:<form:select path="department.id" items="${departments}" itemValue="id" itemLabel="departmentName"></form:select><br>
<input type="submit" value="提交">
</form:form>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有