当前位置:   article > 正文

pdmaner使用模版_it.func.camel(field.defkey,false)

it.func.camel(field.defkey,false)

1.Model

  1. {{ var today=new Date();
  2. var fullYear=today.getFullYear();
  3. var month=today.getMonth() + 1;
  4. var days=today.getDate();
  5. var pkVarName = "undefinedId";
  6. var pkDataType = "String";
  7. it.entity.fields.forEach(function(field){
  8. if(field.primaryKey){
  9. pkVarName = it.func.camel(field.defKey,false);
  10. pkDataType = field["type"];
  11. return;
  12. }
  13. });
  14. var pkgName = it.entity.env.base.nameSpace;
  15. var beanClass = it.entity.env.base.codeRoot;
  16. var beanVarName = beanClass.charAt(0).toLowerCase()+beanClass.slice(1);
  17. var serviceClass = beanClass+'Service';
  18. var serviceVarName= beanVarName+'Service';
  19. }}package {{=pkgName}}.entity;
  20. $blankline
  21. import java.time.LocalDateTime;
  22. import lombok.Data;
  23. import java.math.BigDecimal;
  24. $blankline
  25. /**
  26. * {{=it.entity.defName}};{{=it.entity.comment}}
  27. * @author : heimi
  28. * @date : {{=fullYear}}-{{=month}}-{{=days}}
  29. */
  30. @Data
  31. public class {{=beanClass}} implements BaseModel {
  32. {{~it.entity.fields:field:index}}
  33. /** {{=it.func.join(field.defName,field.comment,';')}} */
  34. private {{=field.type}} {{=it.func.camel(field.defKey,false)}} ;
  35. {{~}}
  36. $blankline
  37. }

2.Dao

  1. {{ var today=new Date();
  2. var fullYear=today.getFullYear();
  3. var month=today.getMonth() + 1;
  4. var days=today.getDate();
  5. var pkVarName = "undefinedId";
  6. var pkDataType = "String";
  7. it.entity.fields.forEach(function(field){
  8. if(field.primaryKey){
  9. pkVarName = it.func.camel(field.defKey,false);
  10. pkDataType = field["type"];
  11. return;
  12. }
  13. });
  14. var pkgName = it.entity.env.base.nameSpace;
  15. var beanClass = it.entity.env.base.codeRoot;
  16. var beanVarName = beanClass.charAt(0).toLowerCase()+beanClass.slice(1);
  17. var serviceClass = beanClass+'Service';
  18. var serviceVarName= beanVarName+'Service';
  19. }}package {{=pkgName}}.mapper;
  20. $blankline
  21. import java.util.List;
  22. import org.apache.ibatis.annotations.Mapper;
  23. import org.apache.ibatis.annotations.Param;
  24. import org.springframework.data.domain.Pageable;
  25. import {{=pkgName}}.model.{{=beanClass}};
  26. $blankline
  27. /**
  28. * {{=it.entity.defName}};({{=it.entity.defKey}})表数据库访问层
  29. * @author : heimi
  30. * @date : {{=fullYear}}-{{=month}}-{{=days}}
  31. */
  32. @Mapper
  33. public interface {{=beanClass}}Dao{
  34. @PageX
  35. List<{{=beanClass}}> select({{=beanClass}}Query query);
  36. Integer insert({{=beanClass}} {{=beanVarName}});
  37. Integer insertBatch(List<{{=beanClass}}> {{=beanVarName}}s);
  38. Integer update({{=beanClass}} {{=beanVarName}});
  39. Integer delete(Integer id);
  40. }

3.Service

  1. {{ var today=new Date();
  2. var fullYear=today.getFullYear();
  3. var month=today.getMonth() + 1;
  4. var days=today.getDate();
  5. var pkVarName = "undefinedId";
  6. var pkVarNameU = "UndefinedId";
  7. var pkDataType = "String";
  8. it.entity.fields.forEach(function(field){
  9. if(field.primaryKey){
  10. pkVarName = it.func.camel(field.defKey,false);
  11. pkVarNameU = it.func.camel(field.defKey,true);
  12. pkDataType = field["type"];
  13. return;
  14. }
  15. });
  16. var pkgName = it.entity.env.base.nameSpace;
  17. var beanClass = it.entity.env.base.codeRoot;
  18. var beanVarName = beanClass.charAt(0).toLowerCase()+beanClass.slice(1);
  19. var serviceClass = beanClass+'Service';
  20. var serviceVarName= beanVarName+'Service';
  21. var daoName = beanVarName+'Dao';
  22. }}package {{=pkgName}}.service;
  23. $blankline
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Service;
  26. import {{=pkgName}}.model.{{=beanClass}};
  27. import {{=pkgName}}.dao.{{=beanClass}}Dao;
  28. import {{=pkgName}}.service.{{=serviceClass}};
  29. /**
  30. * {{=it.entity.defName}};({{=it.entity.defKey}})表服务实现类
  31. * @author : heimi
  32. * @date : {{=fullYear}}-{{=month}}-{{=days}}
  33. */
  34. @Service
  35. public class {{=serviceClass}}Impl implements {{=serviceClass}}{
  36. $blankline
  37. @Autowired
  38. private {{=beanClass}}Dao {{=daoName}};
  39. $blankline
  40. public List<{{=beanClass}}> select({{=beanClass}}Query query) {
  41. return {{=daoName}}.select(query);
  42. }
  43. $blankline
  44. public Integer insert({{=beanClass}} {{=beanVarName}}) {
  45. return {{=daoName}}.insert({{=beanVarName}});
  46. }
  47. $blankline
  48. public Integer update({{=beanClass}} {{=beanVarName}}) {
  49. return {{=daoName}}.update({{=beanVarName}});
  50. }
  51. $blankline
  52. public Integer delete(Integer id) {
  53. return {{=daoName}}.delete(id);
  54. }
  55. }

4.Controller

  1. {{ var today=new Date();
  2. var fullYear=today.getFullYear();
  3. var month=today.getMonth() + 1;
  4. var days=today.getDate();
  5. var pkVarName = "undefinedId";
  6. var pkDataType = "String";
  7. it.entity.fields.forEach(function(field){
  8. if(field.primaryKey){
  9. pkVarName = it.func.camel(field.defKey,false);
  10. pkDataType = field["type"];
  11. return;
  12. }
  13. });
  14. var pkgName = it.entity.env.base.nameSpace;
  15. var beanClass = it.entity.env.base.codeRoot;
  16. var beanVarName = beanClass.charAt(0).toLowerCase()+beanClass.slice(1);
  17. var serviceClass = beanClass+'Service';
  18. var serviceVarName= beanVarName+'Service';
  19. }}package {{=pkgName}}.controller;
  20. $blankline
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.web.bind.annotation.*;
  23. import {{=pkgName}}.model.{{=beanClass}};
  24. import {{=pkgName}}.service.{{=serviceClass}};
  25. $blankline
  26. /**
  27. * {{=it.entity.defName}};({{=it.entity.defKey}})控制层
  28. * @author : heimi
  29. * @date : {{=fullYear}}-{{=month}}-{{=days}}
  30. */
  31. @RestController
  32. @RequestMapping("/api/{{=beanVarName}}")
  33. public class {{=beanClass}}Controller{
  34. @Autowired
  35. private {{=serviceClass}} {{=serviceVarName}};
  36. $blankline
  37. /**
  38. * 查询接口
  39. */
  40. @GetMapping
  41. public List<{{=beanClass}}> select({{=beanClass}}Query query){
  42. return {{=serviceVarName}}.select(query);
  43. }
  44. $blankline
  45. @PostMapping
  46. public Integer insert(@RequestBody {{=beanClass}} product){
  47. return {{=serviceVarName}}.insert(product);
  48. }
  49. $blankline
  50. @PutMapping
  51. public Integer update(@RequestBody {{=beanClass}} product){
  52. return {{=serviceVarName}}.update(product);
  53. }
  54. $blankline
  55. @DeleteMapping
  56. public Integer delete(Integer id){
  57. return {{=serviceVarName}}.delete(id);
  58. }
  59. }

5.Mapper.xml

  1. {{ var today=new Date();
  2. var fullYear=today.getFullYear();
  3. var month=today.getMonth() + 1;
  4. var days=today.getDate();
  5. var pkVarName = "undefinedId";
  6. var pkDataType = "String";
  7. var pkField = "UNDEFINED_ID";
  8. it.entity.fields.forEach(function(field){
  9. if(field.primaryKey){
  10. pkField = field.defKey;
  11. pkVarName = it.func.camel(field.defKey,false);
  12. pkDataType = field["type"];
  13. return;
  14. }
  15. });
  16. var pkgName = it.entity.env.base.nameSpace;
  17. var beanClass = it.entity.env.base.codeRoot;
  18. var beanVarName = beanClass.charAt(0).toLowerCase()+beanClass.slice(1);
  19. var serviceClass = beanClass+'Service';
  20. var serviceVarName= beanVarName+'Service';
  21. }}<?xml version="1.0" encoding="UTF-8"?>
  22. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  23. <mapper namespace="{{=pkgName}}.mapper.{{=beanClass}}Mapper">
  24. <resultMap type="{{=pkgName}}.model.{{=beanClass}}" id="{{=beanClass}}Map">
  25. {{~it.entity.fields:field:index}}
  26. <result property="{{=it.func.camel(field.defKey,false)}}" column="{{=field.defKey}}" />
  27. {{~}}
  28. </resultMap>
  29. $blankline
  30. $blankline
  31. <!--通用查询-->
  32. <select id="select" resultMap="{{=beanClass}}Map">
  33. select
  34. {{=it.entity.fields.map(function(e,i){return e.defKey}).join(',')}}
  35. from {{=it.entity.defKey}}
  36. <where>
  37. {{~it.entity.fields:field:index}}
  38. <if test="{{=it.func.camel(field.defKey,false)}} != null and {{=it.func.camel(field.defKey,false)}} != ''">
  39. and {{=field.defKey}} = #{{{=it.func.camel(field.defKey,false)}}}
  40. </if>
  41. {{~}}
  42. </where>
  43. </select>
  44. $blankline
  45. <!--新增数据-->
  46. <insert id="insert" keyProperty="{{=pkField}}" useGeneratedKeys="true">
  47. insert into {{=it.entity.defKey}}({{=it.entity.fields.map(function(e,i){return e.defKey}).join(',')}})
  48. values ({{=it.entity.fields.map(function(e,i){return '#{'+it.func.camel(e.defKey,false)+'}'}).join(',')}})
  49. </insert>
  50. $blankline
  51. <!-- 批量新增数据 -->
  52. <insert id="insertBatch" keyProperty="{{=pkField}}" useGeneratedKeys="true">
  53. insert into {{=it.entity.defKey}}({{=it.entity.fields.map(function(e,i){return e.defKey}).join(',')}})
  54. values
  55. <foreach collection="entities" item="entity" separator=",">
  56. ({{=it.entity.fields.map(function(e,i){return '#{entity.'+it.func.camel(e.defKey,false)+'}'}).join(',')}})
  57. </foreach>
  58. </insert>
  59. $blankline
  60. <!-- 更新数据 -->
  61. <update id="update">
  62. update {{=it.entity.defKey}}
  63. <set>
  64. {{~it.entity.fields:field:index}}
  65. <if test="{{=it.func.camel(field.defKey,false)}} != null and {{=it.func.camel(field.defKey,false)}} != ''">
  66. {{=field.defKey}} = #{{{=it.func.camel(field.defKey,false)}}},
  67. </if>
  68. {{~}}
  69. </set>
  70. where {{=pkField}} = #{{{=pkVarName}}}
  71. </update>
  72. $blankline
  73. <!--通过主键软删除-->
  74. <update id="delete">
  75. update {{=it.entity.defKey}} set status = 0 where {{=pkField}} = #{{{=pkVarName}}}
  76. </update>
  77. </mapper>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/796304
推荐阅读
相关标签
  

闽ICP备14008679号