package com.java214.controller; import java.beans.PropertyEditorSupport; import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.java214.dao.BookTypeDAO; import com.java214.domain.BookType; //图书类型管理控制层 @Controller @RequestMapping("/BookType") public class BookTypeController { @Resource BookTypeDAO bookTypeDAO; @InitBinder // 必须有一个参数WebDataBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(Date.class, new CustomDateEditor( new SimpleDateFormat("yyyy-MM-dd"), false)); binder.registerCustomEditor(Integer.class, new PropertyEditorSupport() { @Override public String getAsText() { return getValue() == null ? "" : getValue().toString(); } @Override public void setAsText(String text) throws IllegalArgumentException { Integer value = 0; if (null != text && !text.equals("")) { value = Integer.valueOf(text); } setValue(value); } }); } @RequestMapping(value = "/add", method = RequestMethod.GET) public String add(Model model) { model.addAttribute(new BookType()); return "BookType_add"; } @SuppressWarnings("deprecation") @RequestMapping(value = "/add", method = RequestMethod.POST) public String add(@Validated BookType bookType, BindingResult br, Model model, HttpServletRequest request) { if (br.hasErrors()) { model.addAttribute(bookType); return "BookType_add"; } try { bookTypeDAO.AddBookType(bookType); request.setAttribute("message", "图书类型添加成功!"); return "message"; } catch (Exception e) { e.printStackTrace(); request.setAttribute("error","图书类型添加失败!"); return "error"; } } @RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST}) public String list(Integer currentPage, Model model, HttpServletRequest request) { if (currentPage==null || currentPage == 0) currentPage = 1; List<BookType> bookTypeList = bookTypeDAO.QueryBookTypeInfo(currentPage); /* 计算总的页数和总的记录数 */ bookTypeDAO.CalculateTotalPageAndRecordNumber(); /* 获取到总的页码数目 */ int totalPage = bookTypeDAO.getTotalPage(); /* 当前查询条件下总记录数 */ int recordNumber = bookTypeDAO.getRecordNumber(); request.setAttribute("bookTypeList", bookTypeList); request.setAttribute("totalPage", totalPage); request.setAttribute("totalPage", totalPage); request.setAttribute("recordNumber", recordNumber); request.setAttribute("currentPage", currentPage); return "BookType_query_result"; } @RequestMapping(value = { "/frontlist" }, method = {RequestMethod.GET,RequestMethod.POST}) public String frontlist(Integer currentPage, Model model, HttpServletRequest request) { if (currentPage==null || currentPage == 0) currentPage = 1; List<BookType> bookTypeList = bookTypeDAO.QueryBookTypeInfo(currentPage); /* 计算总的页数和总的记录数 */ bookTypeDAO.CalculateTotalPageAndRecordNumber(); /* 获取到总的页码数目 */ int totalPage = bookTypeDAO.getTotalPage(); /* 当前查询条件下总记录数 */ int recordNumber = bookTypeDAO.getRecordNumber(); request.setAttribute("bookTypeList", bookTypeList); request.setAttribute("totalPage", totalPage); request.setAttribute("totalPage", totalPage); request.setAttribute("recordNumber", recordNumber); request.setAttribute("currentPage", currentPage); return "BookType_frontquery_result"; } @RequestMapping(value="/{bookTypeId}/update",method=RequestMethod.GET) public String update(@PathVariable int bookTypeId,Model model) { /*根据主键bookTypeId获取BookType对象*/ BookType bookType = bookTypeDAO.GetBookTypeByBookTypeId(bookTypeId); model.addAttribute(bookType); return "BookType_modify"; } @RequestMapping(value="/{bookTypeId}/frontshow",method=RequestMethod.GET) public String frontshow(@PathVariable int bookTypeId,Model model) { /*根据主键bookTypeId获取BookType对象*/ BookType bookType = bookTypeDAO.GetBookTypeByBookTypeId(bookTypeId); model.addAttribute(bookType); return "BookType_frontshow"; } @RequestMapping(value = "/{bookTypeId}/update", method = RequestMethod.POST) public String update(@Validated BookType bookType, BindingResult br, Model model, HttpServletRequest request) throws UnsupportedEncodingException { if (br.hasErrors()) { model.addAttribute(bookType); return "BookType_modify"; } try { bookTypeDAO.UpdateBookType(bookType); request.setAttribute("message", "图书类型添加成功!"); return "message"; } catch (Exception e) { e.printStackTrace(); request.setAttribute("error", "图书类型添加失败!"); return "error"; } } @RequestMapping(value="/{bookTypeId}/delete",method=RequestMethod.GET) public String delete(@PathVariable int bookTypeId,HttpServletRequest request) throws UnsupportedEncodingException { try { bookTypeDAO.DeleteBookType(bookTypeId); request.setAttribute("message", "图书类型删除成功!"); return "message"; } catch (Exception e) { e.printStackTrace(); request.setAttribute("error","图书类型添加失败!"); return "error"; } } }

Yht2219553 LV2
2024年3月14日
958546428 LV3
2023年11月7日
Seaskye LV14
2023年11月4日
jiemomo LV12
2023年10月18日
zj20020510 LV5
2023年9月14日
huAres LV2
2023年9月3日
最代码官方 LV168
2023年8月25日

PLVAE_514 LV2
3月7日
新哥新奇士橙 LV4
1月26日
asdfg01234 LV10
1月10日
weishenme1993 LV9
1月1日
5454wpg
2024年12月17日
暂无贡献等级
571818771 LV3
2024年12月17日
momomo228 LV2
2024年11月21日
Peny_ZH LV5
2024年9月21日
yimaoermao LV1
2024年9月14日
pangzhihui LV14
2024年6月27日