关注JEECG发展历程 关注最新动态和版本, 记录JEECG成长点滴 更新日志 - 技术支持 - 招聘英才

JEECG最新版本下载 JEECG智能开发平台 - 显著提高开发效率 常见问题 - 入门视频 - 参与开源团队

商务QQ: 69893005、418799587 商务热线(5*8小时): 010-64808099 官方邮箱: jeecgos@163.com

查看: 5467|回复: 0

秀出你的代码风格

[复制链接]
回帖奖励 2 金钱 回复本帖可获得 2 金钱奖励! 每人限 1 次
发表于 2014-7-28 22:10:39 | 显示全部楼层 |阅读模式
自己修改了下Controller版本,改变原因,
1.msg面临的并发危险,
2.ModelAndView基本毫无作用的地位
3.ModelMap代替Request
出来的结果如图,使用了静态变量代替了view
效果如下:




模板如下
  1. package ${bussiPackage}.controller.${entityPackage};
  2. import java.util.List;

  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;

  5. import org.apache.log4j.Logger;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.ResponseBody;

  10. import org.jeecgframework.core.common.controller.BaseController;
  11. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  12. import org.jeecgframework.core.common.model.json.AjaxJson;
  13. import org.jeecgframework.core.common.model.json.DataGrid;
  14. import org.jeecgframework.core.util.StringUtil;
  15. import org.jeecgframework.web.system.service.SystemService;

  16. import ${bussiPackage}.entity.${entityPackage}.${entityName}Entity;
  17. import ${bussiPackage}.service.${entityPackage}.${entityName}ServiceI;

  18. /**   
  19. * @Title: Controller
  20. * @Description: ${ftl_description}
  21. * @author JueYue
  22. * @date ${ftl_create_time}
  23. * @version V1.1
  24. *
  25. */
  26. @Controller
  27. @RequestMapping("/${entityName?uncap_first}Controller")
  28. public class ${entityName}Controller extends BaseController {
  29.         /**
  30.          * Logger for this class
  31.          */
  32.         private static final Logger logger = Logger.getLogger(${entityName}Controller.class);
  33.     //列表界面
  34.     private static final String ${entityName?upper_case}_LIST_PAGE = "${bussiPackage?replace(".","/")}/${entityPackage}/${entityName?uncap_first}List";
  35.     //新增修改界面
  36.     private static final String ${entityName?upper_case}_ADD_OR_UPDATE_PAGE = "${bussiPackage?replace(".","/")}/${entityPackage}/${entityName?uncap_first}";

  37.     @Autowired
  38.         private ${entityName}ServiceI ${entityName?uncap_first}Service;
  39.         @Autowired
  40.         private SystemService systemService;

  41.         /**
  42.          * ${ftl_description}列表 页面跳转
  43.          *
  44.          * @return
  45.          */
  46.         @RequestMapping(params = "${entityName?uncap_first}")
  47.         public String ${entityName?uncap_first}(HttpServletRequest request) {
  48.                 return ${entityName?upper_case}_LIST_PAGE;
  49.         }

  50.         /**
  51.          * easyui AJAX请求数据
  52.          *
  53.          * @param request
  54.          * @param response
  55.          * @param dataGrid
  56.          * @param ${entityName?uncap_first}
  57.          */

  58.         @RequestMapping(params = "datagrid")
  59.         public void datagrid(${entityName}Entity ${entityName?uncap_first},HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  60.                 CriteriaQuery cq = new CriteriaQuery(${entityName}Entity.class, dataGrid);
  61.                 //查询条件组装器
  62.                 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, ${entityName?uncap_first}, request.getParameterMap());
  63.                 this.${entityName?uncap_first}Service.getDataGridReturn(cq, true);
  64.                 TagUtil.datagrid(response, dataGrid);
  65.         }

  66.         /**
  67.          * 删除${ftl_description}
  68.          *
  69.          * @return
  70.          */
  71.         @RequestMapping(params = "del")
  72.         @ResponseBody
  73.         public AjaxJson del(${entityName}Entity ${entityName?uncap_first}, HttpServletRequest request) {
  74.                 AjaxJson j = new AjaxJson();
  75.                 ${entityName?uncap_first} = systemService.getEntity(${entityName}Entity.class, ${entityName?uncap_first}.getId());
  76.         j.setMsg("${ftl_description}删除成功");
  77.                 ${entityName?uncap_first}Service.delete(${entityName?uncap_first});
  78.                 systemService.addLog(j.getMsg(), Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  79.                 return j;
  80.         }


  81.         /**
  82.          * 添加${ftl_description}
  83.          *
  84.          * @param ${entityName?uncap_first}
  85.          * @return
  86.          */
  87.         @RequestMapping(params = "save")
  88.         @ResponseBody
  89.         public AjaxJson save(${entityName}Entity ${entityName?uncap_first}, HttpServletRequest request) {
  90.                 AjaxJson j = new AjaxJson();
  91.                 if (StringUtil.isNotEmpty(${entityName?uncap_first}.getId())) {
  92.             j.setMsg("${ftl_description}更新成功");
  93.                         ${entityName}Entity t = ${entityName?uncap_first}Service.get(${entityName}Entity.class, ${entityName?uncap_first}.getId());
  94.                         try {
  95.                                 MyBeanUtils.copyBeanNotNull2Bean(${entityName?uncap_first}, t);
  96.                                 ${entityName?uncap_first}Service.saveOrUpdate(t);
  97.                                 systemService.addLog(j.getMsg(), Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  98.                         } catch (Exception e) {
  99.                                 e.printStackTrace();
  100.                 j.setMsg("${ftl_description}更新失败");
  101.                         }
  102.                 } else {
  103.             j.setMsg("${ftl_description}添加成功");
  104.                         ${entityName?uncap_first}Service.save(${entityName?uncap_first});
  105.                         systemService.addLog(j.getMsg(), Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  106.                 }
  107.                 return j;
  108.         }

  109.         /**
  110.          * ${ftl_description}列表页面跳转
  111.          *
  112.          * @return
  113.          */
  114.         @RequestMapping(params = "addorupdate")
  115.         public String addorupdate(${entityName}Entity ${entityName?uncap_first}, ModelMap map) {
  116.                 if (StringUtil.isNotEmpty(${entityName?uncap_first}.getId())) {
  117.                         ${entityName?uncap_first} = ${entityName?uncap_first}Service.getEntity(${entityName}Entity.class, ${entityName?uncap_first}.getId());
  118.             map.put("${entityName?uncap_first}Page", ${entityName?uncap_first});
  119.                 }
  120.                 return ${entityName?upper_case}_ADD_OR_UPDATE_PAGE;
  121.         }
  122. }
复制代码
大家也秀出自己的代码风格吧


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表