cgform_controllerTemplate.ftl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <#if packageStyle == "service">
  2. package ${bussiPackage}.${entityPackage}.controller;
  3. import ${bussiPackage}.${entityPackage}.entity.${entityName}Entity;
  4. import ${bussiPackage}.${entityPackage}.service.${entityName}ServiceI;
  5. <#else>
  6. package ${bussiPackage}.controller.${entityPackage};
  7. import ${bussiPackage}.entity.${entityPackage}.${entityName}Entity;
  8. import ${bussiPackage}.service.${entityPackage}.${entityName}ServiceI;
  9. </#if>
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import java.text.SimpleDateFormat;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import org.apache.log4j.Logger;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Controller;
  18. import org.springframework.ui.ModelMap;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.ResponseBody;
  21. import org.springframework.web.servlet.ModelAndView;
  22. import org.jeecgframework.core.common.controller.BaseController;
  23. import org.jeecgframework.core.common.exception.BusinessException;
  24. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  25. import org.jeecgframework.core.common.model.json.AjaxJson;
  26. import org.jeecgframework.core.common.model.json.DataGrid;
  27. import org.jeecgframework.core.constant.Globals;
  28. import org.jeecgframework.core.util.StringUtil;
  29. import org.jeecgframework.tag.core.easyui.TagUtil;
  30. import org.jeecgframework.web.system.pojo.base.TSDepart;
  31. import org.jeecgframework.web.system.service.SystemService;
  32. import org.jeecgframework.core.util.MyBeanUtils;
  33. import java.io.OutputStream;
  34. import org.jeecgframework.core.util.BrowserUtils;
  35. import org.jeecgframework.poi.excel.ExcelExportUtil;
  36. import org.jeecgframework.poi.excel.ExcelImportUtil;
  37. import org.jeecgframework.poi.excel.entity.ExportParams;
  38. import org.jeecgframework.poi.excel.entity.ImportParams;
  39. import org.jeecgframework.poi.excel.entity.TemplateExportParams;
  40. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  41. import org.jeecgframework.poi.excel.entity.vo.TemplateExcelConstants;
  42. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  43. import org.jeecgframework.core.util.ResourceUtil;
  44. import java.io.IOException;
  45. import org.springframework.web.bind.annotation.RequestMethod;
  46. import org.springframework.web.multipart.MultipartFile;
  47. import org.springframework.web.multipart.MultipartHttpServletRequest;
  48. import java.util.Map;
  49. import org.jeecgframework.core.util.ExceptionUtil;
  50. <#-- restful 通用方法生成 -->
  51. import org.springframework.http.ResponseEntity;
  52. import org.springframework.stereotype.Controller;
  53. import org.springframework.web.bind.annotation.PathVariable;
  54. import org.springframework.web.bind.annotation.RequestBody;
  55. import org.springframework.web.bind.annotation.RequestMapping;
  56. import org.springframework.web.bind.annotation.RequestMethod;
  57. import org.springframework.web.bind.annotation.ResponseBody;
  58. import org.springframework.web.bind.annotation.ResponseStatus;
  59. import org.springframework.http.HttpHeaders;
  60. import org.springframework.http.HttpStatus;
  61. import org.jeecgframework.core.beanvalidator.BeanValidators;
  62. import java.util.Set;
  63. import javax.validation.ConstraintViolation;
  64. import javax.validation.Validator;
  65. import java.net.URI;
  66. import org.springframework.http.MediaType;
  67. import org.springframework.web.util.UriComponentsBuilder;
  68. <#-- restful 通用方法生成 -->
  69. <#-- 列为文件类型的文件代码生成 -->
  70. <#assign fileFlag = false />
  71. <#list columns as filePo>
  72. <#if filePo.showType=='file'>
  73. <#assign fileFlag = true />
  74. </#if>
  75. </#list>
  76. <#if fileFlag==true>
  77. import org.jeecgframework.web.cgform.entity.upload.CgUploadEntity;
  78. import org.jeecgframework.web.cgform.service.config.CgFormFieldServiceI;
  79. import java.util.HashMap;
  80. </#if>
  81. <#-- 列为文件类型的文件代码生成 -->
  82. /**
  83. * @Title: Controller
  84. * @Description: ${ftl_description}
  85. * @author onlineGenerator
  86. * @date ${ftl_create_time}
  87. * @version V1.0
  88. *
  89. */
  90. @Controller
  91. @RequestMapping("/${entityName?uncap_first}Controller")
  92. public class ${entityName}Controller extends BaseController {
  93. /**
  94. * Logger for this class
  95. */
  96. private static final Logger logger = Logger.getLogger(${entityName}Controller.class);
  97. @Autowired
  98. private ${entityName}ServiceI ${entityName?uncap_first}Service;
  99. @Autowired
  100. private SystemService systemService;
  101. <#-- restful 通用方法生成 -->
  102. @Autowired
  103. private Validator validator;
  104. <#-- restful 通用方法生成 -->
  105. <#-- 列为文件类型的文件代码生成 -->
  106. <#if fileFlag==true>
  107. @Autowired
  108. private CgFormFieldServiceI cgFormFieldService;
  109. </#if>
  110. <#-- 列为文件类型的文件代码生成 -->
  111. /**
  112. * ${ftl_description}列表 页面跳转
  113. *
  114. * @return
  115. */
  116. @RequestMapping(params = "list")
  117. public ModelAndView list(HttpServletRequest request) {
  118. return new ModelAndView("${bussiPackage?replace(".","/")}/${entityPackage}/${entityName?uncap_first}List");
  119. }
  120. /**
  121. * easyui AJAX请求数据
  122. *
  123. * @param request
  124. * @param response
  125. * @param dataGrid
  126. * @param user
  127. */
  128. @RequestMapping(params = "datagrid")
  129. public void datagrid(${entityName}Entity ${entityName?uncap_first},HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  130. CriteriaQuery cq = new CriteriaQuery(${entityName}Entity.class, dataGrid);
  131. //查询条件组装器
  132. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, ${entityName?uncap_first}, request.getParameterMap());
  133. try{
  134. //自定义追加查询条件
  135. <#list columns as po>
  136. <#if po.isQuery =='Y' && po.queryMode =='group'>
  137. String query_${po.fieldName}_begin = request.getParameter("${po.fieldName}_begin");
  138. String query_${po.fieldName}_end = request.getParameter("${po.fieldName}_end");
  139. if(StringUtil.isNotEmpty(query_${po.fieldName}_begin)){
  140. <#if po.type == "java.util.Date">
  141. cq.ge("${po.fieldName}", new SimpleDateFormat("yyyy-MM-dd").parse(query_${po.fieldName}_begin));
  142. <#else>
  143. cq.ge("${po.fieldName}", Integer.parseInt(query_${po.fieldName}_begin));
  144. </#if>
  145. }
  146. if(StringUtil.isNotEmpty(query_${po.fieldName}_end)){
  147. <#if po.type == "java.util.Date">
  148. cq.le("${po.fieldName}", new SimpleDateFormat("yyyy-MM-dd").parse(query_${po.fieldName}_end));
  149. <#else>
  150. cq.le("${po.fieldName}", Integer.parseInt(query_${po.fieldName}_end));
  151. </#if>
  152. }
  153. </#if>
  154. </#list>
  155. }catch (Exception e) {
  156. throw new BusinessException(e.getMessage());
  157. }
  158. cq.add();
  159. this.${entityName?uncap_first}Service.getDataGridReturn(cq, true);
  160. TagUtil.datagrid(response, dataGrid);
  161. }
  162. /**
  163. * 删除${ftl_description}
  164. *
  165. * @return
  166. */
  167. @RequestMapping(params = "doDel")
  168. @ResponseBody
  169. public AjaxJson doDel(${entityName}Entity ${entityName?uncap_first}, HttpServletRequest request) {
  170. String message = null;
  171. AjaxJson j = new AjaxJson();
  172. ${entityName?uncap_first} = systemService.getEntity(${entityName}Entity.class, ${entityName?uncap_first}.getId());
  173. message = "${ftl_description}删除成功";
  174. try{
  175. ${entityName?uncap_first}Service.delete(${entityName?uncap_first});
  176. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  177. }catch(Exception e){
  178. e.printStackTrace();
  179. message = "${ftl_description}删除失败";
  180. throw new BusinessException(e.getMessage());
  181. }
  182. j.setMsg(message);
  183. return j;
  184. }
  185. /**
  186. * 批量删除${ftl_description}
  187. *
  188. * @return
  189. */
  190. @RequestMapping(params = "doBatchDel")
  191. @ResponseBody
  192. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  193. String message = null;
  194. AjaxJson j = new AjaxJson();
  195. message = "${ftl_description}删除成功";
  196. try{
  197. for(String id:ids.split(",")){
  198. ${entityName}Entity ${entityName?uncap_first} = systemService.getEntity(${entityName}Entity.class,
  199. <#if cgformConfig.cgFormHead.jformPkType?if_exists?html == "UUID">
  200. id
  201. <#elseif cgformConfig.cgFormHead.jformPkType?if_exists?html == "NATIVE">
  202. Integer.parseInt(id)
  203. <#elseif cgformConfig.cgFormHead.jformPkType?if_exists?html == "SEQUENCE">
  204. Integer.parseInt(id)
  205. <#else>
  206. id
  207. </#if>
  208. );
  209. ${entityName?uncap_first}Service.delete(${entityName?uncap_first});
  210. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  211. }
  212. }catch(Exception e){
  213. e.printStackTrace();
  214. message = "${ftl_description}删除失败";
  215. throw new BusinessException(e.getMessage());
  216. }
  217. j.setMsg(message);
  218. return j;
  219. }
  220. /**
  221. * 添加${ftl_description}
  222. *
  223. * @param ids
  224. * @return
  225. */
  226. @RequestMapping(params = "doAdd")
  227. @ResponseBody
  228. public AjaxJson doAdd(${entityName}Entity ${entityName?uncap_first}, HttpServletRequest request) {
  229. String message = null;
  230. AjaxJson j = new AjaxJson();
  231. message = "${ftl_description}添加成功";
  232. try{
  233. ${entityName?uncap_first}Service.save(${entityName?uncap_first});
  234. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  235. }catch(Exception e){
  236. e.printStackTrace();
  237. message = "${ftl_description}添加失败";
  238. throw new BusinessException(e.getMessage());
  239. }
  240. j.setMsg(message);
  241. <#-- 列为文件类型的文件代码生成 -->
  242. <#if fileFlag==true>
  243. j.setObj(${entityName?uncap_first});
  244. </#if>
  245. <#-- 列为文件类型的文件代码生成 -->
  246. return j;
  247. }
  248. /**
  249. * 更新${ftl_description}
  250. *
  251. * @param ids
  252. * @return
  253. */
  254. @RequestMapping(params = "doUpdate")
  255. @ResponseBody
  256. public AjaxJson doUpdate(${entityName}Entity ${entityName?uncap_first}, HttpServletRequest request) {
  257. String message = null;
  258. AjaxJson j = new AjaxJson();
  259. message = "${ftl_description}更新成功";
  260. ${entityName}Entity t = ${entityName?uncap_first}Service.get(${entityName}Entity.class, ${entityName?uncap_first}.getId());
  261. try {
  262. MyBeanUtils.copyBeanNotNull2Bean(${entityName?uncap_first}, t);
  263. ${entityName?uncap_first}Service.saveOrUpdate(t);
  264. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  265. } catch (Exception e) {
  266. e.printStackTrace();
  267. message = "${ftl_description}更新失败";
  268. throw new BusinessException(e.getMessage());
  269. }
  270. j.setMsg(message);
  271. return j;
  272. }
  273. <#list buttons as btn>
  274. <#if btn.optType=='action'>
  275. /**
  276. * 自定义按钮-[${btn.buttonName}]业务
  277. * @param ids
  278. * @return
  279. */
  280. @RequestMapping(params = "do${btn.buttonCode?cap_first}")
  281. @ResponseBody
  282. public AjaxJson do${btn.buttonCode?cap_first}(${entityName}Entity ${entityName?uncap_first}, HttpServletRequest request) {
  283. String message = null;
  284. AjaxJson j = new AjaxJson();
  285. message = "${btn.buttonName}成功";
  286. ${entityName}Entity t = ${entityName?uncap_first}Service.get(${entityName}Entity.class, ${entityName?uncap_first}.getId());
  287. try{
  288. ${entityName?uncap_first}Service.do${btn.buttonCode?cap_first}Bus(t);
  289. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  290. }catch(Exception e){
  291. e.printStackTrace();
  292. message = "${btn.buttonName}失败";
  293. }
  294. j.setMsg(message);
  295. return j;
  296. }
  297. </#if>
  298. </#list>
  299. /**
  300. * ${ftl_description}新增页面跳转
  301. *
  302. * @return
  303. */
  304. @RequestMapping(params = "goAdd")
  305. public ModelAndView goAdd(${entityName}Entity ${entityName?uncap_first}, HttpServletRequest req) {
  306. if (StringUtil.isNotEmpty(${entityName?uncap_first}.getId())) {
  307. ${entityName?uncap_first} = ${entityName?uncap_first}Service.getEntity(${entityName}Entity.class, ${entityName?uncap_first}.getId());
  308. req.setAttribute("${entityName?uncap_first}Page", ${entityName?uncap_first});
  309. }
  310. return new ModelAndView("${bussiPackage?replace(".","/")}/${entityPackage}/${entityName?uncap_first}-add");
  311. }
  312. /**
  313. * ${ftl_description}编辑页面跳转
  314. *
  315. * @return
  316. */
  317. @RequestMapping(params = "goUpdate")
  318. public ModelAndView goUpdate(${entityName}Entity ${entityName?uncap_first}, HttpServletRequest req) {
  319. if (StringUtil.isNotEmpty(${entityName?uncap_first}.getId())) {
  320. ${entityName?uncap_first} = ${entityName?uncap_first}Service.getEntity(${entityName}Entity.class, ${entityName?uncap_first}.getId());
  321. req.setAttribute("${entityName?uncap_first}Page", ${entityName?uncap_first});
  322. }
  323. return new ModelAndView("${bussiPackage?replace(".","/")}/${entityPackage}/${entityName?uncap_first}-update");
  324. }
  325. /**
  326. * 导入功能跳转
  327. *
  328. * @return
  329. */
  330. @RequestMapping(params = "upload")
  331. public ModelAndView upload(HttpServletRequest req) {
  332. req.setAttribute("controller_name","${entityName?uncap_first}Controller");
  333. return new ModelAndView("common/upload/pub_excel_upload");
  334. }
  335. /**
  336. * 导出excel
  337. *
  338. * @param request
  339. * @param response
  340. */
  341. @RequestMapping(params = "exportXls")
  342. public String exportXls(${entityName}Entity ${entityName?uncap_first},HttpServletRequest request,HttpServletResponse response
  343. , DataGrid dataGrid,ModelMap modelMap) {
  344. CriteriaQuery cq = new CriteriaQuery(${entityName}Entity.class, dataGrid);
  345. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, ${entityName?uncap_first}, request.getParameterMap());
  346. List<${entityName}Entity> ${entityName?uncap_first}s = this.${entityName?uncap_first}Service.getListByCriteriaQuery(cq,false);
  347. modelMap.put(NormalExcelConstants.FILE_NAME,"${ftl_description}");
  348. modelMap.put(NormalExcelConstants.CLASS,${entityName}Entity.class);
  349. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("${ftl_description}列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  350. "导出信息"));
  351. modelMap.put(NormalExcelConstants.DATA_LIST,${entityName?uncap_first}s);
  352. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  353. }
  354. /**
  355. * 导出excel 使模板
  356. *
  357. * @param request
  358. * @param response
  359. */
  360. @RequestMapping(params = "exportXlsByT")
  361. public String exportXlsByT(${entityName}Entity ${entityName?uncap_first},HttpServletRequest request,HttpServletResponse response
  362. , DataGrid dataGrid,ModelMap modelMap) {
  363. modelMap.put(NormalExcelConstants.FILE_NAME,"${ftl_description}");
  364. modelMap.put(NormalExcelConstants.CLASS,${entityName}Entity.class);
  365. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("${ftl_description}列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  366. "导出信息"));
  367. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  368. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  369. }
  370. @SuppressWarnings("unchecked")
  371. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  372. @ResponseBody
  373. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  374. AjaxJson j = new AjaxJson();
  375. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  376. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  377. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  378. MultipartFile file = entity.getValue();// 获取上传文件对象
  379. ImportParams params = new ImportParams();
  380. params.setTitleRows(2);
  381. params.setHeadRows(1);
  382. params.setNeedSave(true);
  383. try {
  384. List<${entityName}Entity> list${entityName}Entitys = ExcelImportUtil.importExcel(file.getInputStream(),${entityName}Entity.class,params);
  385. for (${entityName}Entity ${entityName?uncap_first} : list${entityName}Entitys) {
  386. ${entityName?uncap_first}Service.save(${entityName?uncap_first});
  387. }
  388. j.setMsg("文件导入成功!");
  389. } catch (Exception e) {
  390. j.setMsg("文件导入失败!");
  391. logger.error(ExceptionUtil.getExceptionMessage(e));
  392. }finally{
  393. try {
  394. file.getInputStream().close();
  395. } catch (IOException e) {
  396. e.printStackTrace();
  397. }
  398. }
  399. }
  400. return j;
  401. }
  402. <#-- 列为文件类型的文件代码生成 -->
  403. <#if fileFlag==true>
  404. /**
  405. * 获取文件附件信息
  406. *
  407. * @param id ${entityName?uncap_first}主键id
  408. */
  409. @RequestMapping(params = "getFiles")
  410. @ResponseBody
  411. public AjaxJson getFiles(String id){
  412. List<CgUploadEntity> uploadBeans = cgFormFieldService.findByProperty(CgUploadEntity.class, "cgformId", id);
  413. List<Map<String,Object>> files = new ArrayList<Map<String,Object>>(0);
  414. for(CgUploadEntity b:uploadBeans){
  415. String title = b.getAttachmenttitle();//附件名
  416. String fileKey = b.getId();//附件主键
  417. String path = b.getRealpath();//附件路径
  418. String field = b.getCgformField();//表单中作为附件控件的字段
  419. Map<String, Object> file = new HashMap<String, Object>();
  420. file.put("title", title);
  421. file.put("fileKey", fileKey);
  422. file.put("path", path);
  423. file.put("field", field==null?"":field);
  424. files.add(file);
  425. }
  426. AjaxJson j = new AjaxJson();
  427. j.setObj(files);
  428. return j;
  429. }
  430. </#if>
  431. <#-- 列为文件类型的文件代码生成 -->
  432. <#-- restful 通用方法生成 -->
  433. @RequestMapping(method = RequestMethod.GET)
  434. @ResponseBody
  435. public List<${entityName}Entity> list() {
  436. List<${entityName}Entity> list${entityName}s=${entityName?uncap_first}Service.getList(${entityName}Entity.class);
  437. return list${entityName}s;
  438. }
  439. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  440. @ResponseBody
  441. public ResponseEntity<?> get(@PathVariable("id") String id) {
  442. ${entityName}Entity task = ${entityName?uncap_first}Service.get(${entityName}Entity.class, id);
  443. if (task == null) {
  444. return new ResponseEntity(HttpStatus.NOT_FOUND);
  445. }
  446. return new ResponseEntity(task, HttpStatus.OK);
  447. }
  448. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  449. @ResponseBody
  450. public ResponseEntity<?> create(@RequestBody ${entityName}Entity ${entityName?uncap_first}, UriComponentsBuilder uriBuilder) {
  451. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  452. Set<ConstraintViolation<${entityName}Entity>> failures = validator.validate(${entityName?uncap_first});
  453. if (!failures.isEmpty()) {
  454. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  455. }
  456. //保存
  457. try{
  458. ${entityName?uncap_first}Service.save(${entityName?uncap_first});
  459. } catch (Exception e) {
  460. e.printStackTrace();
  461. return new ResponseEntity(HttpStatus.NO_CONTENT);
  462. }
  463. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  464. String id = ${entityName?uncap_first}.getId();
  465. URI uri = uriBuilder.path("/rest/${entityName?uncap_first}Controller/" + id).build().toUri();
  466. HttpHeaders headers = new HttpHeaders();
  467. headers.setLocation(uri);
  468. return new ResponseEntity(headers, HttpStatus.CREATED);
  469. }
  470. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  471. public ResponseEntity<?> update(@RequestBody ${entityName}Entity ${entityName?uncap_first}) {
  472. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  473. Set<ConstraintViolation<${entityName}Entity>> failures = validator.validate(${entityName?uncap_first});
  474. if (!failures.isEmpty()) {
  475. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  476. }
  477. //保存
  478. try{
  479. ${entityName?uncap_first}Service.saveOrUpdate(${entityName?uncap_first});
  480. } catch (Exception e) {
  481. e.printStackTrace();
  482. return new ResponseEntity(HttpStatus.NO_CONTENT);
  483. }
  484. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  485. return new ResponseEntity(HttpStatus.NO_CONTENT);
  486. }
  487. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  488. @ResponseStatus(HttpStatus.NO_CONTENT)
  489. public void delete(@PathVariable("id") String id) {
  490. ${entityName?uncap_first}Service.deleteEntityById(${entityName}Entity.class, id);
  491. }
  492. <#-- restful 通用方法生成 -->
  493. }