个人EasyCode 插件配置
注意:
EasyCode插件版本1.2.4
启用前一定要切换配置为自己的配置
包路径一定要填
配置好现测试生成一下看看结果对不对
{
"author": "JHL",
"version": "1.2.4",
"userSecure": "",
"currTypeMapperGroupName": "Default",
"currTemplateGroupName": "自定义的代码模板",
"currColumnConfigGroupName": "Default",
"currGlobalConfigGroupName": "自定义的代码模板",
"typeMapper": {},
"template": {
"自定义的代码模板": {
"name": "自定义的代码模板",
"elementList": [
{
"name": "controller.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n\n##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"Controller\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/controller\"))\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;\n\nimport $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;\nimport io.swagger.annotations.Api;\nimport io.swagger.annotations.ApiOperation;\nimport io.swagger.annotations.ApiImplicitParam;\nimport io.swagger.annotations.ApiImplicitParams;\nimport org.springframework.web.bind.annotation.RequestBody;\nimport org.springframework.http.ResponseEntity;\nimport org.springframework.web.bind.annotation.*;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport java.util.List;\n\n#tableComment(\"控制器\")\n@Api(tags = \"$!tool.append($tableInfo.comment,\"控制器\")\")\n@RestController\n@RequestMapping(\"/$!tool.firstLowerCase($tableInfo.name)\")\npublic class $!{tableName} {\n\n /**\n * 业务Bean\n */\n @Autowired\n private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;\n\n /**\n * 分页列表查询\n *\n * @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件\n * @return 查询结果\n */\n @ApiOperation(\"列表\")\n @GetMapping(\"/list\")\n public List<$!{tableInfo.name}> list($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.queryAll($!{tool.firstLowerCase($tableInfo.name)});\n }\n\n /**\n * 通过主键查询单条数据\n *\n * @param id 主键\n * @return 单条数据\n */\n @ApiOperation(\"详情\")\n @GetMapping(\"/detail\")\n @ApiImplicitParams({\n @ApiImplicitParam(name = \"id\", value = \"数据唯一标识\", required = true, dataTypeClass = Long.class)\n })\n public $!{tableInfo.name} detail($!pk.shortType id) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id);\n }\n\n /**\n * 新增\n *\n * @param $!{tool.firstLowerCase($tableInfo.name)} 实体\n * @return 新增结果\n */\n @ApiOperation(\"新增\")\n @PostMapping(\"/add\")\n public $!{tableInfo.name} add(@RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.insert($!{tool.firstLowerCase($tableInfo.name)});\n }\n\n /**\n * 更新\n *\n * @param $!{tool.firstLowerCase($tableInfo.name)} 实体\n * @return 编辑结果\n */\n @ApiOperation(\"更新\")\n @PostMapping(\"/edit\")\n public $!{tableInfo.name} edit(@RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.update($!{tool.firstLowerCase($tableInfo.name)});\n }\n\n /**\n * 删除\n *\n * @param id 主键\n * @return 删除是否成功\n */\n @ApiOperation(\"删除\")\n @PostMapping(\"/del\")\n @ApiImplicitParams({\n @ApiImplicitParam(name = \"id\", value = \"数据唯一标识\", required = true, dataTypeClass = Long.class)\n })\n public Boolean del($!pk.shortType id) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.deleteById(id);\n }\n}\n"
},
{
"name": "dao.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n\n##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"Mapper\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/mapper\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mapper;\n\nimport $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};\nimport org.apache.ibatis.annotations.Param;\nimport org.apache.ibatis.annotations.Mapper;\nimport org.springframework.stereotype.Repository;\n\nimport java.util.List;\n\n#tableComment(\"DAO\")\n@Mapper\n@Repository\npublic interface $!{tableName} {\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n $!{tableInfo.name} queryById($!pk.shortType $!pk.name);\n \n /**\n * 按条件查全部\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 查询条件\n * @return 对象列表\n */\n List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 通过主键数组批量查询\n *\n * @param idList\n * @return\n */\n List<$!{tableInfo.name}> findByIds(@Param(\"idList\") List<$!pk.shortType> idList);\n\n /**\n * 统计总行数\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 查询条件\n * @return 总行数\n */\n long count($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 影响行数\n */\n int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 批量新增数据(MyBatis原生foreach方法)\n *\n * @param entities List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n */\n int insertBatch(@Param(\"entities\") List<$!{tableInfo.name}> entities);\n\n /**\n * 批量新增或按主键更新数据(MyBatis原生foreach方法)\n *\n * @param entities List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参\n */\n int insertOrUpdateBatch(@Param(\"entities\") List<$!{tableInfo.name}> entities);\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 影响行数\n */\n int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 影响行数\n */\n int deleteById($!pk.shortType $!pk.name);\n \n}\n"
},
{
"name": "debug.json.vm",
"code": "// 禁止将生成结果写入到文件\n$!callback.setWriteFile(false)\n\n//调试表原始对象\n$!tool.debug($tableInfo.obj)\n\n//调试列原始对象\n$!tool.debug($tableInfo.fullColumn.get(0).obj)\n\n//调试列原始列类型\n$!tool.debug($tableInfo.fullColumn.get(0).obj.dataType)\n\n//获取原始列类型中的字段\nsqlType = $!tool.getField($tableInfo.fullColumn.get(0).obj.dataType, \"typeName\")\n\n//执行原始列类型中的方法\nsqlTypeLen = $!tableInfo.fullColumn.get(0).obj.dataType.getLength()\n"
},
{
"name": "entity.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n\n##使用宏定义设置回调(保存位置与文件后缀)\n#save(\"/entity\", \".java\")\n\n##使用宏定义设置包后缀\n#setPackageSuffix(\"entity\")\n\n##使用全局变量实现默认包导入\n$!{autoImport.vm}\nimport io.swagger.annotations.ApiModel;\nimport io.swagger.annotations.ApiModelProperty;\n\nimport java.io.Serializable;\n\n##使用宏定义实现类注释信息\n#tableComment(\"实体类\")\n@ApiModel(value = \"$!{tableInfo.comment}\")\npublic class $!{tableInfo.name} implements Serializable {\n private static final long serialVersionUID = $!tool.serial();\n \n#foreach($column in $tableInfo.fullColumn)\n #if(${column.comment})\n @ApiModelProperty(name = \"${column.name}\", value = \"${column.comment}\")\n #else\n @ApiModelProperty(name = \"${column.name}\", value = \"\")\n #end\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n \n#end\n\n#foreach($column in $tableInfo.fullColumn)\n##使用宏定义实现get,set方法\n#getSetMethod($column)\n#end\n\n}\n"
},
{
"name": "mapper.xml.vm",
"code": "##引入mybatis支持\n$!{mybatisSupport.vm}\n\n##设置保存名称与保存位置\n$!callback.setFileName($tool.append($!{tableInfo.name}, \"Mapper.xml\"))\n$!callback.setSavePath($tool.append($modulePath, \"/src/main/resources/mapper\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">\n<mapper namespace=\"$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper\">\n\n <resultMap type=\"$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}\" id=\"$!{tableInfo.name}Map\">\n#foreach($column in $tableInfo.fullColumn)\n <result property=\"$!column.name\" column=\"$!column.obj.name\" jdbcType=\"$!column.ext.jdbcType\"/>\n#end\n </resultMap>\n \n <!--表全字段(含主键)-->\n <sql id=\"baseColumnForSelect\">\n #allSqlColumn()\n \n </sql>\n \n <!--表全字段(不含主键)--> \n <sql id=\"baseColumnForInsert\">\n #sqlColumnNotPk()\n \n </sql>\n\n <!--根据主键查一条-->\n <select id=\"queryById\" resultMap=\"$!{tableInfo.name}Map\">\n select \n\t\t<include refid=\"baseColumnForSelect\"/> \n from $!tableInfo.obj.name\n where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}\n </select>\n \n <!--按条件查询全部-->\n <select id=\"queryAll\" resultMap=\"$!{tableInfo.name}Map\">\n select\n\t\t<include refid=\"baseColumnForSelect\"/> \n from $!tableInfo.obj.name\n <where>\n#foreach($column in $tableInfo.fullColumn)\n <if test=\"$!column.name != null#if($column.type.equals(\"java.lang.String\")) and $!column.name != ''#end\">\n and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}\n </if>\n#end\n </where>\n </select>\n \n <!--通过主键数组批量查询-->\n <select id=\"findByIds\" resultMap=\"$!{tableInfo.name}Map\">\n SELECT \n <include refid=\"baseColumnForSelect\"/>\n FROM $!{tableInfo.obj.name} WHERE $!pk.obj.name IN\n <foreach collection=\"idList\" item=\"item\" index=\"index\" open=\"(\" separator=\",\" close=\")\">\n #{item}\n </foreach>\n </select>\n\n <!--按条件统计总行数-->\n <select id=\"count\" resultType=\"java.lang.Long\">\n select count(1)\n from $!tableInfo.obj.name\n <where>\n#foreach($column in $tableInfo.fullColumn)\n <if test=\"$!column.name != null#if($column.type.equals(\"java.lang.String\")) and $!column.name != ''#end\">\n and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}\n </if>\n#end\n </where>\n </select>\n\n <!--新增一条-->\n <insert id=\"insert\" keyProperty=\"$!pk.name\" useGeneratedKeys=\"true\">\n insert into $!{tableInfo.obj.name} (<include refid=\"baseColumnForInsert\"/>)\n values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name},jdbcType=$!{column.ext.jdbcType}}#if($velocityHasNext), #end#end)\n </insert>\n\n <!--批量新增-->\n <insert id=\"insertBatch\" keyProperty=\"$!pk.name\" useGeneratedKeys=\"true\">\n insert into $!{tableInfo.obj.name} (<include refid=\"baseColumnForInsert\"/>)\n values\n <foreach collection=\"entities\" item=\"entity\" separator=\",\">\n (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name},jdbcType=$!{column.ext.jdbcType}}#if($velocityHasNext), #end#end)\n </foreach>\n </insert>\n\n <!--慎用:批量新增或更新-->\n <insert id=\"insertOrUpdateBatch\" keyProperty=\"$!pk.name\" useGeneratedKeys=\"true\">\n insert into $!{tableInfo.obj.name} (<include refid=\"baseColumnForSelect\"/>)\n values\n <foreach collection=\"entities\" item=\"entity\" separator=\",\">\n (#foreach($column in $tableInfo.fullColumn)#{entity.$!{column.name},jdbcType=$!{column.ext.jdbcType}}#if($velocityHasNext), #end#end)\n </foreach>\n on duplicate key update\n #foreach($column in $tableInfo.fullColumn)$!column.obj.name = values($!column.obj.name)#if($velocityHasNext),\n #end#end\n\n </insert>\n\n <!--通过主键条件更新一条-->\n <update id=\"update\">\n update $!{tableInfo.obj.name}\n <set>\n#foreach($column in $tableInfo.otherColumn)\n <if test=\"$!column.name != null#if($column.type.equals(\"java.lang.String\")) and $!column.name != ''#end\">\n $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType},\n </if>\n#end\n </set>\n where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}\n </update>\n\n <!--通过主键删除一条-->\n <delete id=\"deleteById\">\n delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}\n </delete>\n\n</mapper>\n"
},
{
"name": "service.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n\n##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"Service\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/service\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;\n\nimport $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};\nimport java.util.List;\n\n#tableComment(\"业务抽象层\")\npublic interface $!{tableName} {\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n $!{tableInfo.name} queryById($!pk.shortType $!pk.name);\n\n /**\n * 按条件查全部\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 筛选条件\n * @return 查询结果\n */\n List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n \n /**\n * 通过主键数组批量查询\n *\n * @param idList\n * @return\n */\n List<$!{tableInfo.name}> findByIds(List<$!pk.shortType> idList);\n \n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 实例对象\n */\n $!{tableInfo.name} insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 批量新增数据(MyBatis原生foreach方法)\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})s List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n */\n Integer insertBatch(List<$!{tableInfo.name}> $!tool.firstLowerCase($!{tableInfo.name})s);\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 实例对象\n */\n $!{tableInfo.name} update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 是否成功\n */\n Boolean deleteById($!pk.shortType $!pk.name);\n\n}"
},
{
"name": "serviceImpl.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n\n##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"ServiceImpl\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/service/impl\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;\n\nimport $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;\nimport $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;\nimport org.springframework.stereotype.Service;\nimport java.util.List;\nimport org.springframework.beans.factory.annotation.Autowired;\n\n#tableComment(\"业务实现层\")\n@Service\npublic class $!{tableName} implements $!{tableInfo.name}Service {\n\n @Autowired\n private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n @Override\n public $!{tableInfo.name} queryById($!pk.shortType $!pk.name) {\n return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.queryById($!pk.name);\n }\n \n /**\n * 按条件查全部\n *\n * @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件\n * @return 查询结果\n */\n @Override\n public List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {\n return $!{tool.firstLowerCase($tableInfo.name)}Mapper.queryAll($!{tool.firstLowerCase($tableInfo.name)});\n }\n \n /**\n * 通过主键数组批量查询\n *\n * @param idList\n * @return 查询结果\n */\n @Override\n public List<$!{tableInfo.name}> findByIds(List<$!pk.shortType> idList) {\n return $!{tool.firstLowerCase($tableInfo.name)}Mapper.findByIds(idList);\n }\n\n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 实例对象\n */\n @Override\n public $!{tableInfo.name} insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {\n $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insert($!tool.firstLowerCase($!{tableInfo.name}));\n return $!tool.firstLowerCase($!{tableInfo.name});\n }\n \n /**\n * 批量新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})s 实例对象列表\n * @return 影响行数\n */\n @Override\n public Integer insertBatch(List<$!{tableInfo.name}> $!tool.firstLowerCase($!{tableInfo.name})s) {\n return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insertBatch($!tool.firstLowerCase($!{tableInfo.name})s);\n }\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 实例对象\n */\n @Override\n public $!{tableInfo.name} update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {\n this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update($!tool.firstLowerCase($!{tableInfo.name}));\n return queryById($!{tool.firstLowerCase($!{tableInfo.name})}.get$!tool.firstUpperCase($pk.name)());\n }\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 是否成功\n */\n @Override\n public Boolean deleteById($!pk.shortType $!pk.name) {\n return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteById($!pk.name) > 0;\n }\n}"
}
]
}
},
"columnConfig": {},
"globalConfig": {
"自定义的代码模板": {
"name": "自定义的代码模板",
"elementList": [
{
"name": "autoImport.vm",
"value": "##自动导入包(仅导入实体属性需要的包,通常用于实体类)\n#foreach($import in $importList)\nimport $!import;\n#end"
},
{
"name": "define.vm",
"value": "##(Velocity宏定义)\n\n##定义设置表名后缀的宏定义,调用方式:#setTableSuffix(\"Test\")\n#macro(setTableSuffix $suffix)\n #set($tableName = $!tool.append($tableInfo.name, $suffix))\n#end\n\n##定义设置包名后缀的宏定义,调用方式:#setPackageSuffix(\"Test\")\n#macro(setPackageSuffix $suffix)\n#if($suffix!=\"\")package #end#if($tableInfo.savePackageName!=\"\")$!{tableInfo.savePackageName}.#{end}$!suffix;\n#end\n\n##定义直接保存路径与文件名简化的宏定义,调用方式:#save(\"/entity\", \".java\")\n#macro(save $path $fileName)\n $!callback.setSavePath($tool.append($tableInfo.savePath, $path))\n $!callback.setFileName($tool.append($tableInfo.name, $fileName))\n#end\n\n##定义表注释的宏定义,调用方式:#tableComment(\"注释信息\")\n#macro(tableComment $desc)\n/**\n * $!{tableInfo.name} $desc\n * $!{tableInfo.comment}\n *\n * @author $!author\n * @since $!time.currTime(\"yyyy-MM-dd\")\n */\n#end\n\n##定义GET,SET方法的宏定义,调用方式:#getSetMethod($column)\n#macro(getSetMethod $column)\n\n public $!{tool.getClsNameByFullName($column.type)} get$!{tool.firstUpperCase($column.name)}() {\n return $!{column.name};\n }\n\n public void set$!{tool.firstUpperCase($column.name)}($!{tool.getClsNameByFullName($column.type)} $!{column.name}) {\n this.$!{column.name} = $!{column.name};\n }\n#end"
},
{
"name": "init.vm",
"value": "##初始化区域\n\n##去掉表的t_前缀\n$!tableInfo.setName($tool.getClassName($tableInfo.obj.name.replaceFirst(\"book_\",\"\")))\n\n##参考阿里巴巴开发手册,POJO 类中布尔类型的变量,都不要加 is 前缀,否则部分框架解析会引起序列化错误\n#foreach($column in $tableInfo.fullColumn)\n#if($column.name.startsWith(\"is\") && $column.type.equals(\"java.lang.Boolean\"))\n $!column.setName($tool.firstLowerCase($column.name.substring(2)))\n#end\n#end\n\n##实现动态排除列\n#set($temp = $tool.newHashSet(\"testCreateTime\", \"otherColumn\"))\n#foreach($item in $temp)\n #set($newList = $tool.newArrayList())\n #foreach($column in $tableInfo.fullColumn)\n #if($column.name!=$item)\n ##带有反回值的方法调用时使用$tool.call来消除返回值\n $tool.call($newList.add($column))\n #end\n #end\n ##重新保存\n $tableInfo.setFullColumn($newList)\n#end\n\n##对importList进行篡改\n#set($temp = $tool.newHashSet())\n#foreach($column in $tableInfo.fullColumn)\n #if(!$column.type.startsWith(\"java.lang.\"))\n ##带有反回值的方法调用时使用$tool.call来消除返回值\n $tool.call($temp.add($column.type))\n #end\n#end\n##覆盖\n#set($importList = $temp)"
},
{
"name": "mybatisSupport.vm",
"value": "##针对Mybatis 进行支持,主要用于生成xml文件\n#foreach($column in $tableInfo.fullColumn)\n ##储存列类型\n $tool.call($column.ext.put(\"sqlType\", $tool.getField($column.obj.dataType, \"typeName\")))\n #if($tool.newHashSet(\"java.lang.String\").contains($column.type))\n #set($jdbcType=\"VARCHAR\")\n #elseif($tool.newHashSet(\"java.lang.Boolean\", \"boolean\").contains($column.type))\n #set($jdbcType=\"BOOLEAN\")\n #elseif($tool.newHashSet(\"java.lang.Byte\", \"byte\").contains($column.type))\n #set($jdbcType=\"BYTE\")\n #elseif($tool.newHashSet(\"java.lang.Integer\", \"int\", \"java.lang.Short\", \"short\").contains($column.type))\n #set($jdbcType=\"INTEGER\")\n #elseif($tool.newHashSet(\"java.lang.Long\", \"long\").contains($column.type))\n #set($jdbcType=\"INTEGER\")\n #elseif($tool.newHashSet(\"java.lang.Float\", \"float\", \"java.lang.Double\", \"double\").contains($column.type))\n #set($jdbcType=\"NUMERIC\")\n #elseif($tool.newHashSet(\"java.util.Date\", \"java.sql.Timestamp\", \"java.time.Instant\", \"java.time.LocalDateTime\", \"java.time.OffsetDateTime\", \"\tjava.time.ZonedDateTime\").contains($column.type))\n #set($jdbcType=\"TIMESTAMP\")\n #elseif($tool.newHashSet(\"java.sql.Date\", \"java.time.LocalDate\").contains($column.type))\n #set($jdbcType=\"TIMESTAMP\")\n #else\n ##其他类型\n #set($jdbcType=\"VARCHAR\")\n #end\n $tool.call($column.ext.put(\"jdbcType\", $jdbcType))\n#end\n\n##定义宏,查询所有列\n#macro(allSqlColumn)#foreach($column in $tableInfo.fullColumn)$column.obj.name#if($velocityHasNext),#end#end#end\n\n##定义宏,查询所有非主键的列\n#macro(sqlColumnNotPk)#foreach($column in $tableInfo.otherColumn)$column.obj.getName()#if($velocityHasNext),#end#end#end"
}
]
}
}
}
1.2.6版本插件配置
{
"author": "JHL",
"version": "1.2.6",
"userSecure": "",
"currTypeMapperGroupName": "Default",
"currTemplateGroupName": "自定义的代码模板",
"currColumnConfigGroupName": "Default",
"currGlobalConfigGroupName": "自定义的代码模板",
"typeMapper": {},
"template": {
"自定义的代码模板": {
"name": "自定义的代码模板",
"elementList": [
{
"name": "controller.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n\n##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"Controller\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/controller\"))\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;\n\nimport $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;\nimport io.swagger.annotations.Api;\nimport io.swagger.annotations.ApiOperation;\nimport io.swagger.annotations.ApiImplicitParam;\nimport io.swagger.annotations.ApiImplicitParams;\nimport org.springframework.web.bind.annotation.RequestBody;\n\nimport org.springframework.web.bind.annotation.*;\nimport org.springframework.beans.factory.annotation.Autowired;\n\nimport java.util.List;\n\n#tableComment(\"控制器\")\n@Api(tags = \"$!tool.append($tableInfo.comment,\"控制器\")\")\n@RestController\n@RequestMapping(\"/$!tool.firstLowerCase($tableInfo.name)\")\npublic class $!{tableName} {\n\n /**\n * 业务Bean\n */\n @Autowired\n private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;\n\n /**\n * 分页列表查询\n *\n * @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件\n * @return 查询结果\n */\n @ApiOperation(\"列表\")\n @GetMapping(\"/list\")\n public List<$!{tableInfo.name}> list($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.queryAll($!{tool.firstLowerCase($tableInfo.name)});\n }\n\n /**\n * 通过主键查询单条数据\n *\n * @param id 主键\n * @return 单条数据\n */\n @ApiOperation(\"详情\")\n @GetMapping(\"/detail\")\n @ApiImplicitParams({\n @ApiImplicitParam(name = \"id\", value = \"数据唯一标识\", required = true, dataTypeClass = Long.class)\n })\n public $!{tableInfo.name} detail($!pk.shortType id) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id);\n }\n\n /**\n * 新增\n *\n * @param $!{tool.firstLowerCase($tableInfo.name)} 实体\n * @return 新增结果\n */\n @ApiOperation(\"新增\")\n @PostMapping(\"/add\")\n public $!{tableInfo.name} add(@RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.insert($!{tool.firstLowerCase($tableInfo.name)});\n }\n\n /**\n * 更新\n *\n * @param $!{tool.firstLowerCase($tableInfo.name)} 实体\n * @return 编辑结果\n */\n @ApiOperation(\"更新\")\n @PostMapping(\"/edit\")\n public $!{tableInfo.name} edit(@RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.update($!{tool.firstLowerCase($tableInfo.name)});\n }\n\n /**\n * 删除\n *\n * @param id 主键\n * @return 删除是否成功\n */\n @ApiOperation(\"删除\")\n @PostMapping(\"/del\")\n @ApiImplicitParams({\n @ApiImplicitParam(name = \"id\", value = \"数据唯一标识\", required = true, dataTypeClass = Long.class)\n })\n public Boolean del($!pk.shortType id) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.deleteById(id);\n }\n}\n"
},
{
"name": "dao.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n\n##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"Mapper\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/mapper\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mapper;\n\nimport $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};\nimport org.apache.ibatis.annotations.Param;\nimport org.apache.ibatis.annotations.Mapper;\nimport org.springframework.stereotype.Repository;\n\nimport java.util.List;\n\n#tableComment(\"DAO\")\n@Mapper\n@Repository\npublic interface $!{tableName} {\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n $!{tableInfo.name} queryById($!pk.shortType $!pk.name);\n \n /**\n * 按条件查全部\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 查询条件\n * @return 对象列表\n */\n List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 通过主键数组批量查询\n *\n * @param idList\n * @return\n */\n List<$!{tableInfo.name}> queryByIds(@Param(\"idList\") List<$!pk.shortType> idList);\n\n /**\n * 查询当前表未来一条数据的id\n *\n * @return 未来一条数据的id\n */\n Long queryFuturePkNumber();\n\n /**\n * 统计总行数\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 查询条件\n * @return 总行数\n */\n long count($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 影响行数\n */\n int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 批量新增数据\n *\n * @param entities List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n */\n int insertBatch(@Param(\"entities\") List<$!{tableInfo.name}> entities);\n\n /**\n * 批量新增数据(包含主键的)\n *\n * @param entities List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n */\n int insertBatchIncludePK(@Param(\"entities\") List<$!{tableInfo.name}> entities);\n\n /**\n * 批量新增或按主键更新数据(MyBatis原生foreach方法)\n *\n * @param entities List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参\n */\n int insertOrUpdateBatch(@Param(\"entities\") List<$!{tableInfo.name}> entities);\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 影响行数\n */\n int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 影响行数\n */\n int deleteById($!pk.shortType $!pk.name);\n \n /**\n * 批量删除\n *\n * @param idList 主键列表\n */\n void deleteByIds(@Param(\"idList\") List<$!pk.shortType> idList);\n}\n"
},
{
"name": "debug.json.vm",
"code": "// 禁止将生成结果写入到文件\n$!callback.setWriteFile(true)\n\n//调试表原始对象\n$!tool.debug($tableInfo.obj)\n\n//调试列原始对象\n$!tool.debug($tableInfo.fullColumn.get(0).obj)\n\n//调试列原始列类型\n$!tool.debug($tableInfo.fullColumn.get(0).obj.dataType)\n\n//获取原始列类型中的字段\nsqlType = $!tool.getField($tableInfo.fullColumn.get(0).obj.dataType, \"typeName\")\n\n//执行原始列类型中的方法\nsqlTypeLen = $!tableInfo.fullColumn.get(0).obj.dataType.getLength()\n"
},
{
"name": "entity.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n\n##使用宏定义设置回调(保存位置与文件后缀)\n#save(\"/entity\", \".java\")\n\n##使用宏定义设置包后缀\n#setPackageSuffix(\"entity\")\n\n##使用全局变量实现默认包导入\n$!{autoImport.vm}\nimport io.swagger.annotations.ApiModel;\nimport io.swagger.annotations.ApiModelProperty;\n\nimport java.io.Serializable;\n\n##使用宏定义实现类注释信息\n#tableComment(\"实体类\")\n@ApiModel(value = \"$!{tableInfo.comment}\")\npublic class $!{tableInfo.name} implements Serializable {\n private static final long serialVersionUID = $!tool.serial();\n \n#foreach($column in $tableInfo.fullColumn)\n #if(${column.comment})\n @ApiModelProperty(name = \"${column.name}\", value = \"${column.comment}\")\n #else\n @ApiModelProperty(name = \"${column.name}\", value = \"\")\n #end\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n \n#end\n\n#foreach($column in $tableInfo.fullColumn)\n##使用宏定义实现get,set方法\n#getSetMethod($column)\n#end\n\n}\n"
},
{
"name": "mapper.xml.vm",
"code": "##引入mybatis支持\n$!{mybatisSupport.vm}\n\n##设置保存名称与保存位置\n$!callback.setFileName($tool.append($!{tableInfo.name}, \"Mapper.xml\"))\n$!callback.setSavePath($tool.append($projectPath, \"/src/main/resources/mapper\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">\n<mapper namespace=\"$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper\">\n\n <resultMap type=\"$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}\" id=\"$!{tableInfo.name}Map\">\n#foreach($column in $tableInfo.fullColumn)\n <result property=\"$!column.name\" column=\"$!column.obj.name\" jdbcType=\"$!column.ext.jdbcType\"/>\n#end\n </resultMap>\n \n <!--表全字段(含主键)-->\n <sql id=\"baseColumnForSelect\">\n #allSqlColumn()\n \n </sql>\n \n <!--表全字段(不含主键)--> \n <sql id=\"baseColumnForInsert\">\n #sqlColumnNotPk()\n \n </sql>\n\n <!--根据主键查一条-->\n <select id=\"queryById\" resultMap=\"$!{tableInfo.name}Map\">\n select \n\t\t<include refid=\"baseColumnForSelect\"/> \n from $!tableInfo.obj.name\n where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}\n </select>\n \n <!--按条件查询全部-->\n <select id=\"queryAll\" resultMap=\"$!{tableInfo.name}Map\">\n select\n\t\t<include refid=\"baseColumnForSelect\"/> \n from $!tableInfo.obj.name\n <where>\n#foreach($column in $tableInfo.fullColumn)\n <if test=\"$!column.name != null#if($column.type.equals(\"java.lang.String\")) and $!column.name != ''#end\">\n and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}\n </if>\n#end\n </where>\n </select>\n \n <!--通过主键数组批量查询-->\n <select id=\"queryByIds\" resultMap=\"$!{tableInfo.name}Map\">\n SELECT \n <include refid=\"baseColumnForSelect\"/>\n FROM $!{tableInfo.obj.name} WHERE $!pk.obj.name IN\n <foreach collection=\"idList\" item=\"item\" index=\"index\" open=\"(\" separator=\",\" close=\")\">\n #{item}\n </foreach>\n </select>\n \n <!--查询当前表未来一条数据的id-->\n <select id=\"queryFuturePkNumber\" resultType=\"java.lang.Long\">\n SELECT IFNULL(max($!pk.obj.name), 0) + 1 AS maxId\n from $!tableInfo.obj.name\n </select>\n\n <!--按条件统计总行数-->\n <select id=\"count\" resultType=\"java.lang.Long\">\n select count(1)\n from $!tableInfo.obj.name\n <where>\n#foreach($column in $tableInfo.fullColumn)\n <if test=\"$!column.name != null#if($column.type.equals(\"java.lang.String\")) and $!column.name != ''#end\">\n and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}\n </if>\n#end\n </where>\n </select>\n\n <!--新增一条-->\n <insert id=\"insert\" keyProperty=\"$!pk.name\" useGeneratedKeys=\"true\">\n insert into $!{tableInfo.obj.name} (<include refid=\"baseColumnForInsert\"/>)\n values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name},jdbcType=$!{column.ext.jdbcType}}#if($velocityHasNext), #end#end)\n </insert>\n\n <!--批量新增-->\n <insert id=\"insertBatch\" keyProperty=\"$!pk.name\" useGeneratedKeys=\"true\">\n insert into $!{tableInfo.obj.name} (<include refid=\"baseColumnForInsert\"/>)\n values\n <foreach collection=\"entities\" item=\"entity\" separator=\",\">\n (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name},jdbcType=$!{column.ext.jdbcType}}#if($velocityHasNext), #end#end)\n </foreach>\n </insert>\n \n <!--批量新增,含有主键的-->\n <insert id=\"insertBatchIncludePK\">\n insert into $!{tableInfo.obj.name} (<include refid=\"baseColumnForSelect\"/>)\n values\n <foreach collection=\"entities\" item=\"entity\" separator=\",\">\n (#foreach($column in $tableInfo.fullColumn)#{entity.$!{column.name},jdbcType=$!{column.ext.jdbcType}}#if($velocityHasNext), #end#end)\n </foreach>\n </insert>\n\n <!--慎用:批量新增或更新-->\n <insert id=\"insertOrUpdateBatch\" keyProperty=\"$!pk.name\" useGeneratedKeys=\"true\">\n insert into $!{tableInfo.obj.name} (<include refid=\"baseColumnForSelect\"/>)\n values\n <foreach collection=\"entities\" item=\"entity\" separator=\",\">\n (#foreach($column in $tableInfo.fullColumn)#{entity.$!{column.name},jdbcType=$!{column.ext.jdbcType}}#if($velocityHasNext), #end#end)\n </foreach>\n on duplicate key update\n #foreach($column in $tableInfo.fullColumn)$!column.obj.name = values($!column.obj.name)#if($velocityHasNext),\n #end#end\n\n </insert>\n\n <!--通过主键条件更新一条-->\n <update id=\"update\">\n update $!{tableInfo.obj.name}\n <set>\n#foreach($column in $tableInfo.otherColumn)\n <if test=\"$!column.name != null#if($column.type.equals(\"java.lang.String\")) and $!column.name != ''#end\">\n $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType},\n </if>\n#end\n </set>\n where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}\n </update>\n\n <!--通过主键删除一条-->\n <delete id=\"deleteById\">\n delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}\n </delete>\n\n <!--批量删除-->\n <delete id=\"deleteByIds\">\n delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType} IN\n <foreach collection=\"idList\" item=\"item\" index=\"index\" open=\"(\" separator=\",\" close=\")\">\n #{item}\n </foreach>\n </delete>\n</mapper>\n"
},
{
"name": "service.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n\n##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"Service\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/service\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;\n\nimport $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};\nimport java.util.List;\n\n#tableComment(\"业务抽象层\")\npublic interface $!{tableName} {\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n $!{tableInfo.name} queryById($!pk.shortType $!pk.name);\n\n /**\n * 按条件查全部\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 筛选条件\n * @return 查询结果\n */\n List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n \n /**\n * 通过主键数组批量查询\n *\n * @param idList\n * @return\n */\n List<$!{tableInfo.name}> queryByIds(List<$!pk.shortType> idList);\n \n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 实例对象\n */\n $!{tableInfo.name} insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 批量新增数据(MyBatis原生foreach方法)\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})s List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n */\n Integer insertBatch(List<$!{tableInfo.name}> $!tool.firstLowerCase($!{tableInfo.name})s);\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 实例对象\n */\n $!{tableInfo.name} update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 是否成功\n */\n Boolean deleteById($!pk.shortType $!pk.name);\n\n\n /**\n * 批量删除\n *\n * @param idList 主键列表\n */\n void deleteByIds(List<$!pk.shortType> idList);\n}"
},
{
"name": "serviceImpl.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n\n##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"ServiceImpl\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/service/impl\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;\n\nimport $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;\nimport $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\n\nimport java.util.List;\n\n#tableComment(\"业务实现层\")\n@Service\npublic class $!{tableName} implements $!{tableInfo.name}Service {\n\n @Autowired\n private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n @Override\n public $!{tableInfo.name} queryById($!pk.shortType $!pk.name) {\n return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.queryById($!pk.name);\n }\n \n /**\n * 按条件查全部\n *\n * @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件\n * @return 查询结果\n */\n @Override\n public List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {\n return $!{tool.firstLowerCase($tableInfo.name)}Mapper.queryAll($!{tool.firstLowerCase($tableInfo.name)});\n }\n \n /**\n * 通过主键数组批量查询\n *\n * @param idList\n * @return 查询结果\n */\n @Override\n public List<$!{tableInfo.name}> queryByIds(List<$!pk.shortType> idList) {\n return $!{tool.firstLowerCase($tableInfo.name)}Mapper.queryByIds(idList);\n }\n\n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 实例对象\n */\n @Override\n public $!{tableInfo.name} insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {\n $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insert($!tool.firstLowerCase($!{tableInfo.name}));\n return $!tool.firstLowerCase($!{tableInfo.name});\n }\n \n /**\n * 批量新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})s 实例对象列表\n * @return 影响行数\n */\n @Override\n public Integer insertBatch(List<$!{tableInfo.name}> $!tool.firstLowerCase($!{tableInfo.name})s) {\n return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insertBatch($!tool.firstLowerCase($!{tableInfo.name})s);\n }\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 实例对象\n */\n @Override\n public $!{tableInfo.name} update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {\n this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update($!tool.firstLowerCase($!{tableInfo.name}));\n return queryById($!{tool.firstLowerCase($!{tableInfo.name})}.get$!tool.firstUpperCase($pk.name)());\n }\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 是否成功\n */\n @Override\n public Boolean deleteById($!pk.shortType $!pk.name) {\n return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteById($!pk.name) > 0;\n }\n \n /**\n * 批量删除\n *\n * @param idList 主键列表\n */\n @Override\n public void deleteByIds(List<$!pk.shortType> idList) {\n $!{tool.firstLowerCase($tableInfo.name)}Mapper.deleteByIds(idList);\n }\n}"
}
]
}
},
"columnConfig": {},
"globalConfig": {
"自定义的代码模板": {
"name": "自定义的代码模板",
"elementList": [
{
"name": "autoImport.vm",
"value": "##自动导入包(仅导入实体属性需要的包,通常用于实体类)\n#foreach($import in $importList)\nimport $!import;\n#end"
},
{
"name": "define.vm",
"value": "##(Velocity宏定义)\n\n##定义设置表名后缀的宏定义,调用方式:#setTableSuffix(\"Test\")\n#macro(setTableSuffix $suffix)\n #set($tableName = $!tool.append($tableInfo.name, $suffix))\n#end\n\n##定义设置包名后缀的宏定义,调用方式:#setPackageSuffix(\"Test\")\n#macro(setPackageSuffix $suffix)\n#if($suffix!=\"\")package #end#if($tableInfo.savePackageName!=\"\")$!{tableInfo.savePackageName}.#{end}$!suffix;\n#end\n\n##定义直接保存路径与文件名简化的宏定义,调用方式:#save(\"/entity\", \".java\")\n#macro(save $path $fileName)\n $!callback.setSavePath($tool.append($tableInfo.savePath, $path))\n $!callback.setFileName($tool.append($tableInfo.name, $fileName))\n#end\n\n##定义表注释的宏定义,调用方式:#tableComment(\"注释信息\")\n#macro(tableComment $desc)\n/**\n * $!{tableInfo.name} $desc\n * $!{tableInfo.comment}\n *\n * @author $!author\n * @since $!time.currTime(\"yyyy-MM-dd\")\n */\n#end\n\n##定义GET,SET方法的宏定义,调用方式:#getSetMethod($column)\n#macro(getSetMethod $column)\n\n public $!{tool.getClsNameByFullName($column.type)} get$!{tool.firstUpperCase($column.name)}() {\n return $!{column.name};\n }\n\n public void set$!{tool.firstUpperCase($column.name)}($!{tool.getClsNameByFullName($column.type)} $!{column.name}) {\n this.$!{column.name} = $!{column.name};\n }\n#end"
},
{
"name": "init.vm",
"value": "##初始化区域\n\n##去掉表的t_前缀\n$!tableInfo.setName($tool.getClassName($tableInfo.obj.name.replaceFirst(\"book_\",\"\")))\n\n##参考阿里巴巴开发手册,POJO 类中布尔类型的变量,都不要加 is 前缀,否则部分框架解析会引起序列化错误\n#foreach($column in $tableInfo.fullColumn)\n#if($column.name.startsWith(\"is\") && $column.type.equals(\"java.lang.Boolean\"))\n $!column.setName($tool.firstLowerCase($column.name.substring(2)))\n#end\n#end\n\n##实现动态排除列\n#set($temp = $tool.newHashSet(\"testCreateTime\", \"otherColumn\"))\n#foreach($item in $temp)\n #set($newList = $tool.newArrayList())\n #foreach($column in $tableInfo.fullColumn)\n #if($column.name!=$item)\n ##带有反回值的方法调用时使用$tool.call来消除返回值\n $tool.call($newList.add($column))\n #end\n #end\n ##重新保存\n $tableInfo.setFullColumn($newList)\n#end\n\n##对importList进行篡改\n#set($temp = $tool.newHashSet())\n#foreach($column in $tableInfo.fullColumn)\n #if(!$column.type.startsWith(\"java.lang.\"))\n ##带有反回值的方法调用时使用$tool.call来消除返回值\n $tool.call($temp.add($column.type))\n #end\n#end\n##覆盖\n#set($importList = $temp)"
},
{
"name": "mybatisSupport.vm",
"value": "##针对Mybatis 进行支持,主要用于生成xml文件\n#foreach($column in $tableInfo.fullColumn)\n ##储存列类型\n $tool.call($column.ext.put(\"sqlType\", $tool.getField($column.obj.dataType, \"typeName\")))\n #if($tool.newHashSet(\"java.lang.String\").contains($column.type))\n #set($jdbcType=\"VARCHAR\")\n #elseif($tool.newHashSet(\"java.lang.Boolean\", \"boolean\").contains($column.type))\n #set($jdbcType=\"BOOLEAN\")\n #elseif($tool.newHashSet(\"java.lang.Byte\", \"byte\").contains($column.type))\n #set($jdbcType=\"BYTE\")\n #elseif($tool.newHashSet(\"java.lang.Integer\", \"int\", \"java.lang.Short\", \"short\").contains($column.type))\n #set($jdbcType=\"INTEGER\")\n #elseif($tool.newHashSet(\"java.lang.Long\", \"long\").contains($column.type))\n #set($jdbcType=\"INTEGER\")\n #elseif($tool.newHashSet(\"java.lang.Float\", \"float\", \"java.lang.Double\", \"double\").contains($column.type))\n #set($jdbcType=\"NUMERIC\")\n #elseif($tool.newHashSet(\"java.util.Date\", \"java.sql.Timestamp\", \"java.time.Instant\", \"java.time.LocalDateTime\", \"java.time.OffsetDateTime\", \"\tjava.time.ZonedDateTime\").contains($column.type))\n #set($jdbcType=\"TIMESTAMP\")\n #elseif($tool.newHashSet(\"java.sql.Date\", \"java.time.LocalDate\").contains($column.type))\n #set($jdbcType=\"TIMESTAMP\")\n #else\n ##其他类型\n #set($jdbcType=\"VARCHAR\")\n #end\n $tool.call($column.ext.put(\"jdbcType\", $jdbcType))\n#end\n\n##定义宏,查询所有列\n#macro(allSqlColumn)#foreach($column in $tableInfo.fullColumn)`$column.obj.name`#if($velocityHasNext),#end#end#end\n\n##定义宏,查询所有非主键的列\n#macro(sqlColumnNotPk)#foreach($column in $tableInfo.otherColumn)`$column.obj.getName()`#if($velocityHasNext),#end#end#end"
}
]
}
}
}