基于spring-mybatis-data-common基架快速搭建web应用(三)
this.articleService.selectById(id);
map.put("article",article);
} catch (ServiceException e) {
LogHandler.serviceLogError("select entity by id error, id = " + id, e);
}
String viewPath = "article/detail";
return toView(viewPath, map);
}
/**
*
* 支持的请求处理格式
* http://localhost:8080/spring-mybatis-data-common-demo-web/article/delete-2-1325.html
* http://localhost:8080/spring-mybatis-data-common-demo-web/article/2-1325/delete
*
* 删除某页的某个记录
* @param request
* @param response
* @param id
* @return
*/
@RequestMapping(value={"/{pageNow:\\d+}-{id:\\d+}/delete","/delete-{pageNow:\\d+}-{id:\\d+}.html"}, method={RequestMethod.GET})
public ModelAndView deleteArticle(HttpServletRequest request, HttpServletResponse response,@PathVariable("pageNow") Integer pageNow, @PathVariable("id") Long id){
Map map = new HashMap();
try {
int result = this.articleService.deleteById(id);
if(result>0){
LogHandler.ctrlLogInfo("删除记录总数:" + result);
map.put("message", "删除成功");
}
map.put("message", "删除失败");
} catch (ServiceException e) {
LogHandler.serviceLogError("delete entity by id error, id = " + id, e);
map.put("message", "删除失败");
}
String redirectUrl = "../page-" + pageNow + ".html";
return redirectView(redirectUrl);
}
/**
*
* 支持的请求处理格式
* http://localhost:8080/spring-mybatis-data-common-demo-web/article/page-1.html
* http://localhost:8080/spring-mybatis-data-common-demo-web/article/1/page
*
*
* 分页查询
*
* @param request
* @param response
* @param pageNow
* @return
*/
@RequestMapping(value={"/page/{pageNow:\\d+}","page-{pageNow:\\d+}.html"},method={RequestMethod.GET,RequestMethod.POST})
public ModelAndView selectArticle(HttpServletRequest request,HttpServletResponse response,@PathVariable("pageNow") Integer pageNow, @ModelAttribute("article") Article article){
Map map = new HashMap();
Page page = null;
//Article article = new Article();
try {
LogHandler.ctrlLogInfo("查询条件:" + article);
page = this.articleService.selectPage(article, pageNow, pageSize);
System.out.println(page);
map.put("page", page);
List items = page.getItems();
if(null!=items){
for(Article at: items){
LogHandler.ctrlLogInfo(at.getTitle() + "-" + at.getContent());
}
}
} catch (ServiceException e) {
LogHandler.serviceLogError("query by page , condition =" + article,e);
}
String viewPath = "article/lists";
return toView(viewPath, map);
}
/**
* 添加新对象
* @param request
* @param response
* @param article
* @return
*/
@RequestMapping(value={"/add","/add.html"},method={RequestMethod.POST})
public ModelAndView updateArticle(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("article") Article article){
Map map = new HashMap();