JeecgP3demoController.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package com.jeecg.p3.demo.web;
  2. import java.util.UUID;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import org.apache.velocity.VelocityContext;
  6. import org.jeecgframework.minidao.pojo.MiniDaoPage;
  7. import org.jeecgframework.p3.core.common.utils.AjaxJson;
  8. import org.jeecgframework.p3.core.page.SystemTools;
  9. import org.jeecgframework.p3.core.util.plugin.ViewVelocity;
  10. import org.jeecgframework.p3.core.web.BaseController;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.ModelAttribute;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.ResponseBody;
  18. import com.jeecg.p3.demo.entity.JeecgP3demoEntity;
  19. import com.jeecg.p3.demo.service.JeecgP3demoService;
  20. /**
  21. * 描述:P3测试表
  22. * @author: www.jeecg.org
  23. * @since:2017年05月15日 20时07分37秒 星期一
  24. * @version:1.0
  25. */
  26. @Controller
  27. @RequestMapping("/demo/jeecgP3demo")
  28. public class JeecgP3demoController extends BaseController{
  29. @Autowired
  30. private JeecgP3demoService jeecgP3demoService;
  31. /**
  32. * 列表页面
  33. * @return
  34. */
  35. @RequestMapping(params = "list",method = {RequestMethod.GET,RequestMethod.POST})
  36. public void list(@ModelAttribute JeecgP3demoEntity query,HttpServletRequest request,HttpServletResponse response,
  37. @RequestParam(required = false, value = "pageNo", defaultValue = "1") int pageNo,
  38. @RequestParam(required = false, value = "pageSize", defaultValue = "10") int pageSize) throws Exception{
  39. try {
  40. LOG.info(request, " back list");
  41. //分页数据
  42. MiniDaoPage<JeecgP3demoEntity> list = jeecgP3demoService.getAll(query,pageNo,pageSize);
  43. VelocityContext velocityContext = new VelocityContext();
  44. velocityContext.put("jeecgP3demo",query);
  45. velocityContext.put("pageInfos",SystemTools.convertPaginatedList(list));
  46. String viewName = "demo/p3/jeecgP3demo-list.vm";
  47. ViewVelocity.view(request,response,viewName,velocityContext);
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. }
  51. }
  52. /**
  53. * 详情
  54. * @return
  55. */
  56. @RequestMapping(params="toDetail",method = RequestMethod.GET)
  57. public void jeecgP3demoDetail(@RequestParam(required = true, value = "id" ) String id,HttpServletResponse response,HttpServletRequest request)throws Exception{
  58. VelocityContext velocityContext = new VelocityContext();
  59. String viewName = "demo/p3/jeecgP3demo-detail.vm";
  60. JeecgP3demoEntity jeecgP3demo = jeecgP3demoService.get(id);
  61. velocityContext.put("jeecgP3demo",jeecgP3demo);
  62. ViewVelocity.view(request,response,viewName,velocityContext);
  63. }
  64. /**
  65. * 跳转到添加页面
  66. * @return
  67. */
  68. @RequestMapping(params = "toAdd",method ={RequestMethod.GET, RequestMethod.POST})
  69. public void toAddDialog(HttpServletRequest request,HttpServletResponse response)throws Exception{
  70. VelocityContext velocityContext = new VelocityContext();
  71. String viewName = "demo/p3/jeecgP3demo-add.vm";
  72. ViewVelocity.view(request,response,viewName,velocityContext);
  73. }
  74. /**
  75. * 保存信息
  76. * @return
  77. */
  78. @RequestMapping(params = "doAdd",method ={RequestMethod.GET, RequestMethod.POST})
  79. @ResponseBody
  80. public AjaxJson doAdd(@ModelAttribute JeecgP3demoEntity jeecgP3demo){
  81. AjaxJson j = new AjaxJson();
  82. try {
  83. String randomSeed = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
  84. jeecgP3demo.setId(randomSeed);
  85. jeecgP3demoService.insert(jeecgP3demo);
  86. j.setMsg("保存成功");
  87. } catch (Exception e) {
  88. log.info(e.getMessage());
  89. j.setSuccess(false);
  90. j.setMsg("保存失败");
  91. }
  92. return j;
  93. }
  94. /**
  95. * 跳转到编辑页面
  96. * @return
  97. */
  98. @RequestMapping(params="toEdit",method = RequestMethod.GET)
  99. public void toEdit(@RequestParam(required = true, value = "id" ) String id,HttpServletResponse response,HttpServletRequest request) throws Exception{
  100. VelocityContext velocityContext = new VelocityContext();
  101. JeecgP3demoEntity jeecgP3demo = jeecgP3demoService.get(id);
  102. velocityContext.put("jeecgP3demo",jeecgP3demo);
  103. String viewName = "demo/p3/jeecgP3demo-edit.vm";
  104. ViewVelocity.view(request,response,viewName,velocityContext);
  105. }
  106. /**
  107. * 编辑
  108. * @return
  109. */
  110. @RequestMapping(params = "doEdit",method ={RequestMethod.GET, RequestMethod.POST})
  111. @ResponseBody
  112. public AjaxJson doEdit(@ModelAttribute JeecgP3demoEntity jeecgP3demo){
  113. AjaxJson j = new AjaxJson();
  114. try {
  115. jeecgP3demoService.update(jeecgP3demo);
  116. j.setMsg("编辑成功");
  117. } catch (Exception e) {
  118. log.info(e.getMessage());
  119. j.setSuccess(false);
  120. j.setMsg("编辑失败");
  121. }
  122. return j;
  123. }
  124. /**
  125. * 删除
  126. * @return
  127. */
  128. @RequestMapping(params="doDelete",method = RequestMethod.GET)
  129. @ResponseBody
  130. public AjaxJson doDelete(@RequestParam(required = true, value = "id" ) String id){
  131. AjaxJson j = new AjaxJson();
  132. try {
  133. JeecgP3demoEntity jeecgP3demo = new JeecgP3demoEntity();
  134. jeecgP3demo.setId(id);
  135. jeecgP3demoService.delete(jeecgP3demo);
  136. j.setMsg("删除成功");
  137. } catch (Exception e) {
  138. log.info(e.getMessage());
  139. j.setSuccess(false);
  140. j.setMsg("删除失败");
  141. }
  142. return j;
  143. }
  144. }