基础代码

实体Entity

  1. package cn.enilu.material.bean.entity.system;
  2. import cn.enilu.material.bean.entity.BaseEntity;
  3. import lombok.Data;
  4. import org.hibernate.annotations.Table;
  5. import org.springframework.data.jpa.domain.support.AuditingEntityListener;
  6. import javax.persistence.Column;
  7. import javax.persistence.Entity;
  8. import javax.persistence.EntityListeners;
  9. import javax.validation.constraints.NotBlank;
  10. @Entity(name="t_sys_cfg")
  11. @Table(appliesTo = "t_sys_cfg",comment = "系统参数")
  12. @Data
  13. @EntityListeners(AuditingEntityListener.class)
  14. public class Cfg extends BaseEntity {
  15. @Column(name = "cfg_name",columnDefinition = "VARCHAR(256) COMMENT '参数名'")
  16. @NotBlank(message = "参数名不能为空")
  17. private String cfgName;
  18. @Column(name = "cfg_value",columnDefinition = "VARCHAR(512) COMMENT '参数值'")
  19. @NotBlank(message = "参数值不能为空")
  20. private String cfgValue;
  21. @Column(name = "cfg_desc",columnDefinition = "TEXT COMMENT '备注'")
  22. private String cfgDesc;
  23. }

数据库操作Repository

  1. public interface CfgRepository extends BaseRepository<Cfg,Long> {
  2. }

service

  1. @Service
  2. public class CfgService extends BaseService<Cfg,Long,CfgRepository> {
  3. }

controller

  1. @Controller
  2. @RequestMapping("/cfg")
  3. public class CfgController extends BaseController {
  4. @Autowired
  5. private CfgService cfgService;
  6. private static String PREFIX = "/system/cfg/";
  7. /**
  8. * 跳转到参数首页
  9. */
  10. @RequestMapping("")
  11. public String index() {
  12. return PREFIX + "cfg.html";
  13. }
  14. /**
  15. * 跳转到添加参数
  16. */
  17. @RequestMapping("/cfg_add")
  18. public String add() {
  19. return PREFIX + "cfg_add.html";
  20. }
  21. /**
  22. * 跳转到修改参数
  23. */
  24. @RequestMapping("/cfg_update/{cfgId}")
  25. public String update(@PathVariable Long cfgId, Model model) {
  26. Cfg cfg = cfgService.get(cfgId);
  27. model.addAttribute("item",cfg);
  28. return PREFIX + "cfg_edit.html";
  29. }
  30. /**
  31. * 获取参数列表
  32. */
  33. @RequestMapping(value = "/list")
  34. @ResponseBody
  35. public Object list(@RequestParam(required = false) String cfgName, @RequestParam(required = false) String cfgValue) {
  36. Page<Cfg> page = new PageFactory<Cfg>().defaultPage();
  37. if(StringUtils.isNotEmpty(cfgName)){
  38. page.addFilter(SearchFilter.build("cfgName", SearchFilter.Operator.LIKE, cfgName));
  39. }
  40. if(StringUtils.isNotEmpty(cfgValue)){
  41. page.addFilter(SearchFilter.build("cfgValue", SearchFilter.Operator.LIKE, cfgValue));
  42. }
  43. page = cfgService.queryPage(page);
  44. return packForBT(page);
  45. }
  46. /**
  47. * 新增参数
  48. */
  49. @RequestMapping(value = "/add")
  50. @ResponseBody
  51. @BussinessLog(value = "添加参数", key = "cfgName",dict = CfgDict.class)
  52. public Object add(@Valid Cfg cfg) {
  53. cfgService.saveOrUpdate(cfg);
  54. return SUCCESS_TIP;
  55. }
  56. /**
  57. * 删除参数
  58. */
  59. @RequestMapping(value = "/delete")
  60. @ResponseBody
  61. @BussinessLog(value = "删除参数", key = "cfgId",dict = CfgDict.class)
  62. public Object delete(@RequestParam Long cfgId) {
  63. cfgService.delete(cfgId);
  64. return SUCCESS_TIP;
  65. }
  66. /**
  67. * 修改参数
  68. */
  69. @RequestMapping(value = "/update")
  70. @ResponseBody
  71. @BussinessLog(value = "编辑参数", key = "cfgName",dict = CfgDict.class)
  72. public Object update(@Valid Cfg cfg) {
  73. cfgService.update(cfg);
  74. return SUCCESS_TIP;
  75. }
  76. /**
  77. * 参数详情
  78. */
  79. @RequestMapping(value = "/detail/{cfgId}")
  80. @ResponseBody
  81. public Object detail(@PathVariable("cfgId") Long cfgId) {
  82. return cfgService.get(cfgId);
  83. }