formController.ftl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <#import "function.ftl" as func>
  2. <#assign package=model.variables.package>
  3. <#assign class=model.variables.class>
  4. <#assign system=vars.system>
  5. <#assign comment=model.tabComment>
  6. <#assign classVar=model.variables.classVar>
  7. <#assign pk=func.getPk(model) >
  8. <#assign pkVar=func.convertUnderLine(pk) >
  9. <#assign pkVarFistUp=pkVar?cap_first >
  10. <#assign subtables=model.subTableList>
  11. package ${vars.packagePre}.${system}.controller.${package};
  12. import java.util.HashMap;
  13. import java.util.Map;
  14. import javax.annotation.Resource;
  15. import javax.servlet.http.HttpServletRequest;
  16. import javax.servlet.http.HttpServletResponse;
  17. import org.springframework.stereotype.Controller;
  18. import org.springframework.web.bind.annotation.ModelAttribute;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RequestParam;
  21. import ${vars.packagePre}.core.annotion.Action;
  22. import ${vars.packagePre}.core.util.UniqueIdUtil;
  23. import ${vars.packagePre}.core.web.ResultMessage;
  24. import ${vars.packagePre}.core.web.util.RequestUtil;
  25. import ${vars.packagePre}.core.web.controller.BaseFormController;
  26. import ${vars.packagePre}.${system}.model.${package}.${class};
  27. import ${vars.packagePre}.${system}.service.${package}.${class}Service;
  28. <#if func.isSubTableExist( subtables)>
  29. <#list subtables as table>
  30. import ${vars.packagePre}.${system}.model.${package}.${table.variables.class};
  31. </#list>
  32. </#if>
  33. /**
  34. *<pre>
  35. * 对象功能:${comment} 控制器类
  36. <#if vars.company?exists>
  37. * 开发公司:${vars.company}
  38. </#if>
  39. <#if vars.developer?exists>
  40. * 开发人员:${vars.developer}
  41. </#if>
  42. * 创建时间:${date?string("yyyy-MM-dd HH:mm:ss")}
  43. *</pre>
  44. */
  45. @Controller
  46. @RequestMapping("/${system}/${package}/${classVar}/")
  47. public class ${class}FormController extends BaseFormController
  48. {
  49. @Resource
  50. private ${class}Service ${classVar}Service;
  51. /**
  52. * 添加或更新项目信息。
  53. * @param request
  54. * @param response
  55. * @param projectInfo 添加或更新的实体
  56. * @return
  57. * @throws Exception
  58. */
  59. @RequestMapping("save")
  60. @Action(description="添加或更新项目信息")
  61. public void save(HttpServletRequest request, HttpServletResponse response,${class} ${classVar}) throws Exception
  62. {
  63. String resultMsg=null;
  64. try{
  65. if(${classVar}.get${pkVarFistUp}()==null||${classVar}.get${pkVarFistUp}()==0){
  66. ${classVar}Service.save(${classVar});
  67. resultMsg=getText("添加","项目信息");
  68. }else{
  69. ${classVar}Service.save(${classVar});
  70. resultMsg=getText("更新","项目信息");
  71. }
  72. writeResultMessage(response.getWriter(),resultMsg,ResultMessage.Success);
  73. }catch(Exception e){
  74. writeResultMessage(response.getWriter(),resultMsg,ResultMessage.Fail);
  75. }
  76. }
  77. /**
  78. * 在实体对象进行封装前,从对应源获取原实体
  79. * @param projectId
  80. * @param model
  81. * @return
  82. * @throws Exception
  83. */
  84. @ModelAttribute
  85. protected ${class} getObject(@RequestParam("${pkVar}") Long ${pkVar}) throws Exception {
  86. logger.debug("enter ${class} getFormObject here....");
  87. ${class} ${classVar}=null;
  88. if(${pkVar}!=null){
  89. ${classVar}=${classVar}Service.getById(${pkVar});
  90. }else{
  91. ${classVar}= new ${class}();
  92. }
  93. return ${classVar};
  94. }
  95. }