相比于其他类别的工程师,软件工程师最大的优势就是可以开发提高生产力的工具,加更少的班,节约更多的时间用于提升自己。
在此分享一下工作以来的几种加快开发速度的工具,希望对大家有所帮助~
开发中有些语句我们经常用到,每次完整敲一遍很麻烦,这种情况我们可以定义一些缩写词来简化这些语句。
先看效果:
它的大致原理就是把常见的代码段简写为几个字母,在用的时候只需要敲这几个字母,按下回车,就可以替换为对应的代码段了。当然还有一些高级的用法,留给读者自行研究。
关于使用教程,网上有很多教程,这里不做赘述,只粘贴两个:
idea living template 简单使用
idea living template 进阶使用
有时候有些文件结构类似,比如枚举类,controller,service等等,每新建一个这种文件的时候需要重复定义结构很麻烦,我们可以把这个结构定义成一个模板,新建文件的时候直接根据模板生成。
还是先看效果,比如新建一个自定义的枚举类
它的大致原理就是预先定义一套模板,预设一些参数,在生成文件的时候填充相应的参数,就可以直接生成对应的文件。
它的配置路径是:File -> Setting -> Editor -> File and code Templates, 如下:
定义模板的方法可以参考idea自带的模板,依葫芦画瓢就能懂个大概,就不详细说明了。
这里粘贴一下我经常使用的模板:
一、枚举类模板
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
/**
* ${description}
* @author lq 80296710
* @date ${DATE}
*/
public enum ${NAME} {
SAMPLE("value","desc"),
;
private final String value;
private final String desc;
${NAME}(final String value, final String desc) {
this.value = value;
this.desc = desc;
}
public String value() {
return this.value;
}
public String desc() {
return this.desc;
}
public static String getValue(String desc) {
${NAME}[] enums = values();
for (${NAME} e : enums) {
if (e.desc.equals(desc)) {
return e.value;
}
}
return null;
}
public static String getDesc(String value) {
${NAME}[] enums = values();
for (${NAME} e : enums) {
if (e.value.equals(value)) {
return e.desc;
}
}
return null;
}
}
二、实体类模板
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
/**
* ${description}
* @author lq 80296710
* @date ${DATE}
*/
@Data
@SuperBuilder
@NoArgsConstructor
public class ${NAME} {
}
简单提一句,这里实体类模板用到了lombok插件,且生成的代码没有导入lombok的包,可设置idea的导入方式为autoImport,这样生成该类的时候就会自动导入lombok的包。设置自动导入如下:
有时候我们发现,项目中不仅代码语句有相似的、代码文件有相似的,甚至连代码结构也有相似的。比如做web开发,mapper层、dao层、service层,结构是固定的,只要数据库表确定了,这些底层的代码也基本确定了,所以完全可以用插件生成。
简介:easyCode是一款代码生成插件,它具有读取数据库表的功能,可以自定义生成dao层、mapper层、service层等等。有人可能要问,它和mybatis-generator有什么区别?区别在于,mybatis-generator生成的代码自定义空间小,可能不符合项目组的开发规范,导致生成之后还需要手动修改,而easyCode生成的代码可以按照项目组的规范自定义,生成之后不需要修改,一步到位,非常方便。easyCode本身没有和任何框架绑定,即是说,我们可以用它来生成任何文本类型的文件,包括xml、json等等。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dao.StudentDao">
<resultMap type="entity.Student" id="BaseResultMap">
<result property="id" column="ID" jdbcType="VARCHAR"/>
<result property="name" column="NAME" jdbcType="VARCHAR"/>
<result property="age" column="AGE" jdbcType="INTEGER"/>
<result property="updateTime" column="UPDATE_TIME" jdbcType="VARCHAR"/>
<result property="createTime" column="CREATE_TIME" jdbcType="VARCHAR"/>
<result property="version" column="VERSION" jdbcType="INTEGER"/>
</resultMap>
<sql id = "Base_Column_List">
ID, NAME, AGE, UPDATE_TIME, CREATE_TIME, VERSION
</sql>
<!--基础过滤条件-->
<sql id = "Base_Filter">
<if test="id != null and id != ''">
and ID = #{id}
</if>
<if test="name != null and name != ''">
and NAME = #{name}
</if>
<if test="age != null">
and AGE = #{age}
</if>
<if test="updateTime != null and updateTime != ''">
and UPDATE_TIME = #{updateTime}
</if>
<if test="createTime != null and createTime != ''">
and CREATE_TIME = #{createTime}
</if>
<if test="version != null">
and VERSION = #{version}
</if>
</sql>
<sql id = "Alia_Base_Filter">
<if test="studentQuery.id != null and studentQuery.id != ''">
and student.ID = #{studentQuery.id}
</if>
<if test="studentQuery.name != null and studentQuery.name != ''">
and student.NAME = #{studentQuery.name}
</if>
<if test="studentQuery.age != null">
and student.AGE = #{studentQuery.age}
</if>
<if test="studentQuery.updateTime != null and studentQuery.updateTime != ''">
and student.UPDATE_TIME = #{studentQuery.updateTime}
</if>
<if test="studentQuery.createTime != null and studentQuery.createTime != ''">
and student.CREATE_TIME = #{studentQuery.createTime}
</if>
<if test="studentQuery.version != null">
and student.VERSION = #{studentQuery.version}
</if>
</sql>
<!--扩展过滤条件-->
<sql id = "Extend_Filter">
</sql>
<sql id = "Alia_Extend_Filter">
</sql>
<!--查询单个-->
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
select
<include refid = "Base_Column_List"/>
from STUDENT
where ID = #{id}
</select>
<!--查询指定行数据-->
<select id="selectSelective" resultMap="BaseResultMap">
select
<include refid = "Base_Column_List"/>
from STUDENT
<where>
<include refid="Base_Filter"/>
<include refid="Extend_Filter"/>
</where>
<choose>
<when test="orderField != null and orderField != '' ">
ORDER BY ${orderField} ${orderType}
</when>
<otherwise>
ORDER BY CREATE_TIME DESC
</otherwise>
</choose>
</select>
<!--统计总行数-->
<select id="selectCount" resultType="java.lang.Long">
select count(1)
from STUDENT
<where>
<include refid="Base_Filter"/>
<include refid="Extend_Filter"/>
</where>
</select>
<!--新增列-->
<insert id="insertSelective" keyProperty="" useGeneratedKeys="true">
insert into STUDENT
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">
ID,
</if>
<if test="name != null and name != ''">
NAME,
</if>
<if test="age != null">
AGE,
</if>
<if test="updateTime != null and updateTime != ''">
UPDATE_TIME,
</if>
<if test="createTime != null and createTime != ''">
CREATE_TIME,
</if>
<if test="version != null">
VERSION,
</if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">
#{id},
</if>
<if test="name != null and name != ''">
#{name},
</if>
<if test="age != null">
#{age},
</if>
<if test="updateTime != null and updateTime != ''">
#{updateTime},
</if>
<if test="createTime != null and createTime != ''">
#{createTime},
</if>
<if test="version != null">
#{version},
</if>
</trim>
</insert>
<!--通过主键修改数据-->
<update id="updateByPrimaryKeySelective">
update STUDENT
<set>
<if test="name != null and name != ''">
NAME = #{name},
</if>
<if test="age != null">
AGE = #{age},
</if>
<if test="updateTime != null and updateTime != ''">
UPDATE_TIME = #{updateTime},
</if>
<if test="createTime != null and createTime != ''">
CREATE_TIME = #{createTime},
</if>
<if test="version != null">
VERSION = #{version},
</if>
</set>
where ID = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteByPrimaryKey">
delete from STUDENT where ID = #{id}
</delete>
</mapper>
/**
* (Student)数据库访问对象
*
* @author lq 80296710
* @since 2022-08-19
*/
@Repository
public interface StudentDao {
/**
* 查询单条数据(by primaryKey)
*
* @return 实例对象
*/
Student selectByPrimaryKey();
/**
* 查询指定行数据
*
* @param studentQuery 查询条件
* @return 对象列表
*/
List<Student> selectSelective(StudentQuery studentQuery);
/**
* 统计总行数
*
* @param studentQuery 查询条件
* @return 总行数
*/
long selectCount(StudentQuery studentQuery);
/**
* 新增数据
*
* @param student 实例对象
* @return 影响行数
*/
int insertSelective(Student student);
/**
* 修改数据
*
* @param student 实例对象
* @return 影响行数
*/
int updateByPrimaryKeySelective(Student student);
/**
* 通过主键删除数据
*
* @return 影响行数
*/
int deleteByPrimaryKey();
}
import java.io.Serializable;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* (Student)实体类
*
* @author lq 80296710
* @since 2022-08-19
*/
@SuperBuilder
@NoArgsConstructor
@Data
public class Student implements Serializable {
private static final long serialVersionUID = -22821126137687615L;
/**
* id
*/
protected String id;
/**
* 姓名
*/
protected String name;
/**
* 年龄
*/
protected Integer age;
/**
* 更新时间
*/
protected String updateTime;
/**
* 创建时间
*/
protected String createTime;
/**
* 版本号
*/
protected Integer version;
}
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* (Student)查询对象
*
* @author lq 80296710
* @since 2022-08-19
*/
@SuperBuilder
@NoArgsConstructor
@Data
public class StudentQuery extends Student{
}
/**
* (Student)基础服务
*
* @author lq 80296710
* @since 2022-08-19
*/
public interface StudentBaseService {
/**
* 查询单条数据
*
* @return 实例对象
*/
Student selectByPrimaryKey();
/**
* 查询批量数据
*
* @param studentQuery 筛选条件
* @return 查询结果
*/
List<Student> selectList(StudentQuery studentQuery);
/**
* 查询总条数
*
* @param studentQuery 筛选条件
* @return 总条数
*/
long selectCount(StudentQuery studentQuery);
/**
* 新增数据
*
* @param student 实例对象
* @return 影响的行数
*/
int save(Student student);
/**
* 修改单条数据
*
* @param student 实例对象
* @return 影响的行数
*/
int update(Student student);
/**
* 通过主键删除数据
*
* @return 影响的行数
*/
int deleteByPrimaryKey();
}
/**
* (Student)基础服务实现类
*
* @author lq 80296710
* @since 2022-08-19
*/
@Service
public class StudentBaseServiceImpl implements StudentBaseService {
@Autowired
private StudentDao studentDao;
/**
* 查询单条数据
*
* @return 实例对象
*/
@Override
public Student selectByPrimaryKey() {
return studentDao.selectByPrimaryKey();
}
/**
* 查询批量数据
*
* @param studentQuery 筛选条件
* @return 查询结果
*/
@Override
public List<Student> selectList(StudentQuery studentQuery) {
if(Objects.equals(studentQuery, new StudentQuery())){
throw new RuntimeException("selectSelective参数不能全为空,业务逻辑异常");
}
return studentDao.selectSelective(studentQuery);
}
@Override
public long selectCount(StudentQuery studentQuery){
return studentDao.selectCount(studentQuery);
}
/**
* 新增数据
*
* @param student 实例对象
* @return 影响的行数
*/
@Override
public int save(Student student) {
return studentDao.insertSelective(student);
}
/**
* 修改数据
*
* @param student 实例对象
* @return 影响的行数
*/
@Override
public int update(Student student) {
return studentDao.updateByPrimaryKeySelective(student);
}
/**
* 通过主键删除数据
*
* @return 影响的行数
*/
@Override
public int deleteByPrimaryKey() {
return studentDao.deleteByPrimaryKey();
}
}
上述是笔者工作当中的工作规范下所生成的代码模板,读者也可以根据自己工作当中的规范自定义模板。
easyCode的安装和使用教程网上很多,比如下面这个
easyCode安装和使用教程
上述效果图中笔者使用的easyCode配置如下
{
"author" : "lq 80296710",
"version" : "1.2.4",
"userSecure" : "",
"currTypeMapperGroupName" : "Default",
"currTemplateGroupName" : "Default",
"currColumnConfigGroupName" : "Default",
"currGlobalConfigGroupName" : "entWallet",
"typeMapper" : {
"Default" : {
"name" : "Default",
"elementList" : [ {
"matchType" : "REGEX",
"columnType" : "varchar(\\(\\d+\\))?",
"javaType" : "java.lang.String"
}, {
"matchType" : "REGEX",
"columnType" : "char(\\(\\d+\\))?",
"javaType" : "java.lang.String"
}, {
"matchType" : "REGEX",
"columnType" : "(tiny|medium|long)*text",
"javaType" : "java.lang.String"
}, {
"matchType" : "REGEX",
"columnType" : "decimal(\\(\\d+,\\d+\\))?",
"javaType" : "java.lang.Double"
}, {
"matchType" : "ORDINARY",
"columnType" : "integer",
"javaType" : "java.lang.Integer"
}, {
"matchType" : "REGEX",
"columnType" : "(tiny|small|medium)*int(\\(\\d+\\))?",
"javaType" : "java.lang.Integer"
}, {
"matchType" : "ORDINARY",
"columnType" : "int4",
"javaType" : "java.lang.Integer"
}, {
"matchType" : "ORDINARY",
"columnType" : "int8",
"javaType" : "java.lang.Long"
}, {
"matchType" : "REGEX",
"columnType" : "bigint(\\(\\d+\\))?",
"javaType" : "java.lang.Long"
}, {
"matchType" : "ORDINARY",
"columnType" : "date",
"javaType" : "java.util.Date"
}, {
"matchType" : "ORDINARY",
"columnType" : "datetime",
"javaType" : "java.util.Date"
}, {
"matchType" : "ORDINARY",
"columnType" : "timestamp",
"javaType" : "java.util.Date"
}, {
"matchType" : "ORDINARY",
"columnType" : "time",
"javaType" : "java.time.LocalTime"
}, {
"matchType" : "ORDINARY",
"columnType" : "boolean",
"javaType" : "java.lang.Boolean"
}, {
"matchType" : "REGEX",
"columnType" : "VARCHAR2\\(\\d+\\)",
"javaType" : "java.lang.String"
}, {
"matchType" : "REGEX",
"columnType" : "NUMBER\\(\\d+\\)",
"javaType" : "java.lang.Long"
}, {
"matchType" : "REGEX",
"columnType" : "NUMBER\\(\\d+,\\d+\\)",
"javaType" : "java.math.BigDecimal"
}, {
"matchType" : "ORDINARY",
"columnType" : "CLOB",
"javaType" : "java.lang.String"
}, {
"matchType" : "REGEX",
"columnType" : "TIMESTAMP\\(\\d+\\)",
"javaType" : "java.time.LocalDateTime"
} ]
}
},
"template" : {
"MybatisPlus-Mixed" : {
"name" : "MybatisPlus-Mixed",
"elementList" : [ {
"name" : "controller.java.vm",
"code" : "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"Controller\")\n\n##保存文件(宏定义)\n#save(\"/controller\", \"Controller.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"controller\")\n\n##定义服务名\n#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), \"Service\"))\n\n##定义实体对象名\n#set($entityName = $!tool.firstLowerCase($!tableInfo.name))\n\nimport com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;\nimport com.baomidou.mybatisplus.extension.api.ApiController;\nimport com.baomidou.mybatisplus.extension.api.R;\nimport com.baomidou.mybatisplus.extension.plugins.pagination.Page;\nimport $!{tableInfo.savePackageName}.entity.$!tableInfo.name;\nimport $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;\nimport org.springframework.web.bind.annotation.*;\n\nimport javax.annotation.Resource;\nimport java.io.Serializable;\nimport java.util.List;\n\n##表注释(宏定义)\n#tableComment(\"表控制层\")\n@RestController\n@RequestMapping(\"$!tool.firstLowerCase($!tableInfo.name)\")\npublic class $!{tableName} extends ApiController {\n /**\n * 服务对象\n */\n @Resource\n private $!{tableInfo.name}Service $!{serviceName};\n\n /**\n * 分页查询所有数据\n *\n * @param page 分页对象\n * @param $!entityName 查询实体\n * @return 所有数据\n */\n @GetMapping\n public R selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) {\n return success(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName)));\n }\n\n /**\n * 通过主键查询单条数据\n *\n * @param id 主键\n * @return 单条数据\n */\n @GetMapping(\"{id}\")\n public R selectOne(@PathVariable Serializable id) {\n return success(this.$!{serviceName}.getById(id));\n }\n\n /**\n * 新增数据\n *\n * @param $!entityName 实体对象\n * @return 新增结果\n */\n @PostMapping\n public R insert(@RequestBody $!tableInfo.name $!entityName) {\n return success(this.$!{serviceName}.save($!entityName));\n }\n\n /**\n * 修改数据\n *\n * @param $!entityName 实体对象\n * @return 修改结果\n */\n @PutMapping\n public R update(@RequestBody $!tableInfo.name $!entityName) {\n return success(this.$!{serviceName}.updateById($!entityName));\n }\n\n /**\n * 删除数据\n *\n * @param idList 主键结合\n * @return 删除结果\n */\n @DeleteMapping\n public R delete(@RequestParam(\"idList\") List idList) {\n return success(this.$!{serviceName}.removeByIds(idList));\n }\n}\n"
}, {
"name" : "dao.java.vm",
"code" : "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"Dao\")\n\n##保存文件(宏定义)\n#save(\"/dao\", \"Dao.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"dao\")\n\nimport java.util.List;\n\nimport com.baomidou.mybatisplus.core.mapper.BaseMapper;\nimport org.apache.ibatis.annotations.Param;\nimport $!{tableInfo.savePackageName}.entity.$!tableInfo.name;\n\n##表注释(宏定义)\n#tableComment(\"表数据库访问层\")\npublic interface $!{tableName} extends BaseMapper<$!tableInfo.name> {\n\n/**\n* 批量新增数据(MyBatis原生foreach方法)\n*\n* @param entities List<$!{tableInfo.name}> 实例对象列表\n* @return 影响行数\n*/\nint 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*/\nint insertOrUpdateBatch(@Param(\"entities\") List<$!{tableInfo.name}> entities);\n\n}\n"
}, {
"name" : "entity.java.vm",
"code" : "##导入宏定义\n$!{define.vm}\n\n##保存文件(宏定义)\n#save(\"/entity\", \".java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"entity\")\n\n##自动导入包(全局变量)\n$!autoImport\nimport com.baomidou.mybatisplus.extension.activerecord.Model;\nimport java.io.Serializable;\n\n##表注释(宏定义)\n#tableComment(\"表实体类\")\n@SuppressWarnings(\"serial\")\npublic class $!{tableInfo.name} extends Model<$!{tableInfo.name}> {\n#foreach($column in $tableInfo.fullColumn)\n #if(${column.comment})//${column.comment}#end\n\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n#end\n\n#foreach($column in $tableInfo.fullColumn)\n#getSetMethod($column)\n#end\n\n#foreach($column in $tableInfo.pkColumn)\n /**\n * 获取主键值\n *\n * @return 主键值\n */\n @Override\n protected Serializable pkVal() {\n return this.$!column.name;\n }\n #break\n#end\n}\n"
}, {
"name" : "mapper.xml.vm",
"code" : "##引入mybatis支持\n$!{mybatisSupport.vm}\n\n##设置保存名称与保存位置\n$!callback.setFileName($tool.append($!{tableInfo.name}, \"Dao.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\n\n\n\n \n#foreach($column in $tableInfo.fullColumn)\n \n#end\n \n\n \n \n insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)\n values\n \n (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)\n \n \n \n \n insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)\n values\n \n (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)\n \n on duplicate key update\n #foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name) #if($velocityHasNext), #end#end\n \n\n \n"
}, {
"name" : "service.java.vm",
"code" : "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"Service\")\n\n##保存文件(宏定义)\n#save(\"/service\", \"Service.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"service\")\n\nimport com.baomidou.mybatisplus.extension.service.IService;\nimport $!{tableInfo.savePackageName}.entity.$!tableInfo.name;\n\n##表注释(宏定义)\n#tableComment(\"表服务接口\")\npublic interface $!{tableName} extends IService<$!tableInfo.name> {\n\n}\n"
}, {
"name" : "serviceImpl.java.vm",
"code" : "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"ServiceImpl\")\n\n##保存文件(宏定义)\n#save(\"/service/impl\", \"ServiceImpl.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"service.impl\")\n\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;\nimport $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;\nimport org.springframework.stereotype.Service;\n\n##表注释(宏定义)\n#tableComment(\"表服务实现类\")\n@Service(\"$!tool.firstLowerCase($tableInfo.name)Service\")\npublic class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Dao, $!{tableInfo.name}> implements $!{tableInfo.name}Service {\n\n}\n"
} ]
},
"MybatisPlus" : {
"name" : "MybatisPlus",
"elementList" : [ {
"name" : "controller.java.vm",
"code" : "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"Controller\")\n\n##保存文件(宏定义)\n#save(\"/controller\", \"Controller.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"controller\")\n\n##定义服务名\n#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), \"Service\"))\n\n##定义实体对象名\n#set($entityName = $!tool.firstLowerCase($!tableInfo.name))\n\nimport com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;\nimport com.baomidou.mybatisplus.extension.api.ApiController;\nimport com.baomidou.mybatisplus.extension.api.R;\nimport com.baomidou.mybatisplus.extension.plugins.pagination.Page;\nimport $!{tableInfo.savePackageName}.entity.$!tableInfo.name;\nimport $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;\nimport org.springframework.web.bind.annotation.*;\n\nimport javax.annotation.Resource;\nimport java.io.Serializable;\nimport java.util.List;\n\n##表注释(宏定义)\n#tableComment(\"表控制层\")\n@RestController\n@RequestMapping(\"$!tool.firstLowerCase($!tableInfo.name)\")\npublic class $!{tableName} extends ApiController {\n /**\n * 服务对象\n */\n @Resource\n private $!{tableInfo.name}Service $!{serviceName};\n\n /**\n * 分页查询所有数据\n *\n * @param page 分页对象\n * @param $!entityName 查询实体\n * @return 所有数据\n */\n @GetMapping\n public R selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) {\n return success(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName)));\n }\n\n /**\n * 通过主键查询单条数据\n *\n * @param id 主键\n * @return 单条数据\n */\n @GetMapping(\"{id}\")\n public R selectOne(@PathVariable Serializable id) {\n return success(this.$!{serviceName}.getById(id));\n }\n\n /**\n * 新增数据\n *\n * @param $!entityName 实体对象\n * @return 新增结果\n */\n @PostMapping\n public R insert(@RequestBody $!tableInfo.name $!entityName) {\n return success(this.$!{serviceName}.save($!entityName));\n }\n\n /**\n * 修改数据\n *\n * @param $!entityName 实体对象\n * @return 修改结果\n */\n @PutMapping\n public R update(@RequestBody $!tableInfo.name $!entityName) {\n return success(this.$!{serviceName}.updateById($!entityName));\n }\n\n /**\n * 删除数据\n *\n * @param idList 主键结合\n * @return 删除结果\n */\n @DeleteMapping\n public R delete(@RequestParam(\"idList\") List idList) {\n return success(this.$!{serviceName}.removeByIds(idList));\n }\n}\n"
}, {
"name" : "dao.java.vm",
"code" : "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"Dao\")\n\n##保存文件(宏定义)\n#save(\"/dao\", \"Dao.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"dao\")\n\nimport com.baomidou.mybatisplus.core.mapper.BaseMapper;\nimport $!{tableInfo.savePackageName}.entity.$!tableInfo.name;\n\n##表注释(宏定义)\n#tableComment(\"表数据库访问层\")\npublic interface $!{tableName} extends BaseMapper<$!tableInfo.name> {\n\n}\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 com.baomidou.mybatisplus.extension.activerecord.Model;\nimport java.io.Serializable;\n\n##表注释(宏定义)\n#tableComment(\"表实体类\")\n@SuppressWarnings(\"serial\")\npublic class $!{tableInfo.name} extends Model<$!{tableInfo.name}> {\n#foreach($column in $tableInfo.fullColumn)\n #if(${column.comment})//${column.comment}#end\n\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n#end\n\n#foreach($column in $tableInfo.fullColumn)\n#getSetMethod($column)\n#end\n\n#foreach($column in $tableInfo.pkColumn)\n /**\n * 获取主键值\n *\n * @return 主键值\n */\n @Override\n protected Serializable pkVal() {\n return this.$!column.name;\n }\n #break\n#end\n}\n"
}, {
"name" : "service.java.vm",
"code" : "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"Service\")\n\n##保存文件(宏定义)\n#save(\"/service\", \"Service.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"service\")\n\nimport com.baomidou.mybatisplus.extension.service.IService;\nimport $!{tableInfo.savePackageName}.entity.$!tableInfo.name;\n\n##表注释(宏定义)\n#tableComment(\"表服务接口\")\npublic interface $!{tableName} extends IService<$!tableInfo.name> {\n\n}\n"
}, {
"name" : "serviceImpl.java.vm",
"code" : "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"ServiceImpl\")\n\n##保存文件(宏定义)\n#save(\"/service/impl\", \"ServiceImpl.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"service.impl\")\n\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;\nimport $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;\nimport org.springframework.stereotype.Service;\n\n##表注释(宏定义)\n#tableComment(\"表服务实现类\")\n@Service(\"$!tool.firstLowerCase($tableInfo.name)Service\")\npublic class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Dao, $!{tableInfo.name}> implements $!{tableInfo.name}Service {\n\n}\n"
} ]
},
"spring-data-mongodb" : {
"name" : "spring-data-mongodb",
"elementList" : [ {
"name" : "controller.java.vm",
"code" : "##导入宏定义、设置包名、类名、文件名##导入宏定义\n$!{define.vm}\n#setPackageSuffix(\"controller\")\n#setTableSuffix(\"Controller\")\n#save(\"/controller\", \"Controller.java\")\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n##定义服务名\n#set($serviceSortType = $!tool.append($!tableInfo.name, \"Service\"))\n#set($serviceType = $!tool.append($!tableInfo.savePackageName, \".service.\", $serviceSortType))\n#set($serviceVarName = $!tool.firstLowerCase($serviceSortType))\n\n#set($entityShortType = $!tableInfo.name)\n#set($entityType = $!tableInfo.psiClassObj.getQualifiedName())\n#set($entityVarName = $!tool.firstLowerCase($!tableInfo.name))\n#set($pkType = $!pk.type)\n\nimport $pkType;\nimport $entityType;\nimport $serviceType;\nimport lombok.AllArgsConstructor;\nimport org.springframework.data.domain.Page;\nimport org.springframework.data.domain.Pageable;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.PostMapping;\nimport org.springframework.web.bind.annotation.RequestBody;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n\n/**\n * $!{tableInfo.comment}控制层\n *\n * @author $!author\n * @since $!time.currTime()\n */\n@RestController\n@RequestMapping(\"/$!tool.firstLowerCase($!tableInfo.name)\")\n@AllArgsConstructor\npublic class $!{tableName} {\n\n\tprivate $serviceSortType $serviceVarName;\n\n\t/**\n\t * 获取$!{tableInfo.comment}列表(分页)\n\t */\n\t@GetMapping(\"/list\")\n\tpublic Page<$entityShortType> list(Pageable page) {\n\t\treturn null;\n\t}\n\n\t/**\n\t * 获取$!{tableInfo.comment}\n\t */\n\t@GetMapping(\"/get\")\n\tpublic $entityShortType get($!pk.shortType id) {\n\t\treturn ${serviceVarName}.findById(id);\n\t}\n\n\t/**\n\t * 添加$!{tableInfo.comment}\n\t */\n\t@PostMapping(\"/add\")\n\tpublic void add(@RequestBody $entityShortType $entityVarName) {\n\t\t${serviceVarName}.save($entityVarName);\n\t}\n\n\n\t/**\n\t * 修改$!{tableInfo.comment}\n\t */\n\t@PostMapping(\"/update\")\n\tpublic void update(@RequestBody $entityShortType $entityVarName) {\n\t\t${serviceVarName}.save($entityVarName);\n\t}\n\n\t/**\n\t * 删除$!{tableInfo.comment}\n\t */\n\t@PostMapping(\"/delete\")\n\tpublic void delete($!pk.shortType id) {\n\t\t${serviceVarName}.deleteById(id);\n\t}\n\n}\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 java.io.Serializable;\n\n##使用宏定义实现类注释信息\n#tableComment(\"实体类\")\npublic class $!{tableInfo.name} implements Serializable {\n private static final long serialVersionUID = $!tool.serial();\n#foreach($column in $tableInfo.fullColumn)\n #if(${column.comment})/**\n * ${column.comment}\n */#end\n\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n#end\n\n#foreach($column in $tableInfo.fullColumn)\n##使用宏定义实现get,set方法\n#getSetMethod($column)\n#end\n\n}\n"
}, {
"name" : "repository.java.vm",
"code" : "##导入宏定义、设置包名、类名、文件名##导入宏定义\n$!{define.vm}\n#setPackageSuffix(\"repository\")\n#setTableSuffix(\"Repository\")\n#save(\"/repository\", \"Repository.java\")\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n##实体类名、主键类名\n#set($entityShortType = $!tableInfo.name)\n#set($entityType = $!tableInfo.psiClassObj.getQualifiedName())\n#set($pkShortType = $!pk.shortType)\n#set($pkType = $!pk.type)\n\nimport $pkType;\nimport $entityType;\nimport org.springframework.data.mongodb.repository.MongoRepository;\n\n\n/**\n * $!{tableInfo.comment}持久层\n *\n * @author $!author\n * @since $!time.currTime()\n */\npublic interface $!{tableName} extends MongoRepository<$entityShortType, $pkShortType> {\n\n}\n"
}, {
"name" : "service.java.vm",
"code" : "##导入宏定义、设置包名、类名、文件名##导入宏定义\n$!{define.vm}\n#setPackageSuffix(\"service\")\n#setTableSuffix(\"Service\")\n#save(\"/service\", \"Service.java\")\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n##实体类名、主键类名\n#set($entityShortType = $!tableInfo.name)\n#set($entityType = $!tableInfo.psiClassObj.getQualifiedName())\n#set($entityVarName = $!tool.firstLowerCase($!tableInfo.name))\n#set($pkShortType = $!pk.shortType)\n#set($pkType = $!pk.type)\n\nimport $pkType;\nimport $entityType;\nimport org.springframework.data.domain.Page;\nimport org.springframework.data.domain.Pageable;\nimport java.util.Collection;\nimport java.util.List;\n\n\n/**\n * $!{tableInfo.comment}业务层\n *\n * @author $!author\n * @since $!time.currTime()\n */\npublic interface $!{tableName} {\n\n void save($entityShortType $entityVarName);\n\n void deleteById($pkShortType id);\n\n $entityShortType findById($pkShortType id);\n\n List<$entityShortType> findById(Collection<$pkShortType> ids);\n\n Page<$entityShortType> list(Pageable page);\n\n}\n"
}, {
"name" : "serviceImpl.java.vm",
"code" : "##导入宏定义、设置包名、类名、文件名\n$!{define.vm}\n#setPackageSuffix(\"service.impl\")\n#setTableSuffix(\"ServiceImpl\")\n#save(\"/service/impl\", \"ServiceImpl.java\")\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n##业务层类名、持久层类名、实体名\n#set($serviceSortType = $!tool.append($!tableInfo.name, \"Service\"))\n#set($serviceType = $!tool.append($!tableInfo.savePackageName, \".service.\", $serviceSortType))\n#set($repositorySortType = $!tool.append($!tableInfo.name, \"Repository\"))\n#set($repositoryType = $!tool.append($!tableInfo.savePackageName, \".repository.\", $repositorySortType))\n#set($repositoryVarName = $!tool.firstLowerCase($!repositorySortType))\n#set($entityShortType = $!tableInfo.name)\n#set($entityType = $!tableInfo.psiClassObj.getQualifiedName())\n#set($entityVarName = $!tool.firstLowerCase($!tableInfo.name))\n#set($pkShortType = $!pk.shortType)\n#set($pkType = $!pk.type)\n\nimport $pkType;\nimport $entityType;\nimport $serviceType;\nimport $repositoryType;\nimport org.springframework.stereotype.Service;\nimport javax.annotation.Resource;\nimport org.springframework.data.domain.Page;\nimport org.springframework.data.domain.Pageable;\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.stream.Collectors;\nimport java.util.stream.StreamSupport;\n\n\n/**\n * $!{tableInfo.comment}业务层\n *\n * @author $!author\n * @since $!time.currTime()\n */\n@Service\npublic class $!{tableName} implements $!serviceSortType {\n\n\t@Resource\n private $repositorySortType $repositoryVarName;\n\n @Override\n public void save($entityShortType $entityVarName) {\n $!{repositoryVarName}.save($entityVarName);\n }\n\n @Override\n public void deleteById($pkShortType id) {\n $!{repositoryVarName}.delete(id);\n }\n\n @Override\n public $entityShortType findById($pkShortType id) {\n return $!{repositoryVarName}.findOne(id);\n }\n\n @Override\n public List<$entityShortType> findById(Collection<$pkShortType> ids) {\n Iterable<$entityShortType> iterable = $!{repositoryVarName}.findAll(ids);\n return StreamSupport.stream(iterable.spliterator(), false)\n .collect(Collectors.toList());\n }\n\n @Override\n public Page<$entityShortType> list(Pageable page) {\n return $!{repositoryVarName}.findAll(page);\n }\n\n}\n"
} ]
},
"Default" : {
"name" : "Default",
"elementList" : [ {
"name" : "entity.java.vm",
"code" : "##引入宏定义\n$!{define.vm}\n$!{daoDefine.vm}\n$!{globalValue.vm}\n\n##设置保存路径&文件名\n$!callback.setSavePath($!{entitySavePath})\n$!callback.setFileName($!{entityFileName})\n\n##包路径\n#if($entityPackageName!=\"\")package #end$!entityPackageName;\n\n##使用全局变量实现默认包导入\n$!{autoImport.vm}\nimport java.io.Serializable;\nimport lombok.Data;\nimport lombok.NoArgsConstructor;\nimport lombok.experimental.SuperBuilder;\n\n##使用宏定义实现类注释信息\n#tableComment(\"实体类\")\n@SuperBuilder\n@NoArgsConstructor\n@Data\npublic class $!entityClassName implements Serializable {\n private static final long serialVersionUID = $!tool.serial();\n#foreach($column in $tableInfo.fullColumn)\n #if(${column.comment})/**\n * ${column.comment}\n */#end\n\n protected $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n#end\n}\n"
}, {
"name" : "query.java.vm",
"code" : "##引入宏定义\n$!{define.vm}\n$!{daoDefine.vm}\n$!{globalValue.vm}\n\n##设置保存路径&文件名\n$!callback.setSavePath($!{querySavePath})\n$!callback.setFileName($!{queryFileName})\n\n##包路径\n#if($queryPackageName!=\"\")package #end$!queryPackageName;\n\n##使用全局变量实现默认包导入\n$!{autoImport.vm}\nimport $!{entityFullyClassName};\nimport lombok.Data;\nimport lombok.NoArgsConstructor;\nimport lombok.experimental.SuperBuilder;\n\n##使用宏定义实现类注释信息\n#tableComment(\"查询对象\")\n@SuperBuilder\n@NoArgsConstructor\n@Data\npublic class $!{queryClassName} extends $!{tableInfo.name}{\n /**\n * 排序字段\n */\n String orderField;\n /**\n * 排序类型\n */\n String orderType;\n}\n"
}, {
"name" : "dao.java.vm",
"code" : "##引入宏定义\n$!{define.vm}\n$!{daoDefine.vm}\n$!{globalValue.vm}\n\n##设置保存路径&文件名\n$!callback.setSavePath($!{daoSavePath})\n$!callback.setFileName($!{daoFileName})\n\n##包路径\n#if($daoPackageName!=\"\")package #end$!daoPackageName;\n\n\nimport $!{entityFullyClassName};\nimport $!{queryFullyClassName};\nimport java.util.List;\nimport org.springframework.stereotype.Repository;\n\n##使用宏定义实现类注释信息\n#tableComment(\"数据库访问对象\")\n@Repository\npublic interface $!{daoClassName} {\n\n /**\n * 查询单条数据(by primaryKey)\n * \n#foreach($pk in $pks)\n * @param $!pk.name $!pk.comment\n#end\n * @return 实例对象\n */\n $!{entityClassName} $!{selectByPrimaryKey}(#foreach($pk in $pks)$!pk.shortType $!pk.name#if($velocityCount != $pks.size()), #end#end);\n\n /**\n * 查询指定行数据\n *\n * @param $!{queryInstanceName} 查询条件\n * @return 对象列表\n */\n List<$!{entityClassName}> ${selectSelective}($!{queryClassName} $!{queryInstanceName});\n\n /**\n * 统计总行数\n *\n * @param $!{queryInstanceName} 查询条件\n * @return 总行数\n */\n long ${count}($!{queryClassName} $!{queryInstanceName});\n\n /**\n * 新增数据\n *\n * @param $!{entityInstanceName} 实例对象\n * @return 影响行数\n */\n int ${insertSelective}($!{entityClassName} $!{entityInstanceName});\n\n /**\n * 修改数据\n *\n * @param $!{entityInstanceName} 实例对象\n * @return 影响行数\n */\n int ${updateByPrimaryKeySelective}($!{entityClassName} $!{entityInstanceName});\n\n /**\n * 通过主键删除数据\n *\n#foreach($pk in $pks)\n * @param $!pk.name $!pk.comment\n#end\n * @return 影响行数\n */\n int ${deleteByPrimaryKey}(#foreach($pk in $pks)$!pk.shortType $!pk.name#if($velocityCount != $pks.size()), #end#end);\n\n}\n"
}, {
"name" : "mapper.xml.vm",
"code" : "##引入mybatis支持\n$!{mybatisSupport.vm}\n##引入宏定义\n$!{define.vm}\n$!{daoDefine.vm}\n$!{globalValue.vm}\n\n##设置保存名称与保存位置\n$!callback.setFileName($!{mapperFileName})\n$!callback.setSavePath($!{mapperSavePath})\n\n\n\n\n\n \n#foreach($column in $tableInfo.fullColumn)\n \n#end\n \n\n \n #allSqlColumn()\n \n \n \n \n \n#foreach($column in $tableInfo.fullColumn)\n \n and $!column.obj.name = #{$!column.name}\n \n#end\n \n \n \n \n #foreach($column in $tableInfo.fullColumn)\n \n and $entityInstanceName.$!column.obj.name = #{$queryInstanceName.$!column.name}\n \n#end \n \n \n \n \n \n \n \n \n \n \n\n \n \n\n \n \n\n \n \n insert into $!{FullySchemaName}$!{tableInfo.obj.name}\n \n#foreach($column in $tableInfo.fullColumn)\n \n $!column.obj.name,\n \n#end\n \n values \n \n #foreach($column in $tableInfo.fullColumn)\n \n #{$!column.name},\n \n#end\n \n \n\n \n \n update $!{FullySchemaName}$!{tableInfo.obj.name}\n \n#foreach($column in $tableInfo.otherColumn)\n \n $!column.obj.name = #{$!column.name},\n \n#end\n \n where #foreach($pk in $pks)$!pk.obj.name = #{$!pk.name}#if($velocityCount != $pks.size()) and #end#end\n \n \n\n \n \n delete from $!{FullySchemaName}$!{tableInfo.obj.name} where #foreach($pk in $pks)$!pk.obj.name = #{$!pk.name}#if($velocityCount != $pks.size()) and #end#end\n \n \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" : "baseService.java.vm",
"code" : "##引入宏定义\n$!{define.vm}\n$!{daoDefine.vm}\n$!{globalValue.vm}\n\n##设置保存路径&文件名\n$!callback.setSavePath($!{baseServiceSavePath})\n$!callback.setFileName($!{baseServiceFileName})\n\n##包路径\n#if($baseServicePackageName!=\"\")package #end$!baseServicePackageName;\n\n\nimport $!{entityFullyClassName};\nimport $!{queryFullyClassName};\nimport java.util.List;\n\n##使用宏定义实现类注释信息\n#tableComment(\"基础服务\")\npublic interface $!{baseServiceClassName} {\n\n /**\n * 查询单条数据\n *\n#foreach($pk in $pks)\n * @param $!pk.name $!pk.comment\n#end\n * @return 实例对象\n */\n $!{entityClassName} selectByPrimaryKey(#foreach($pk in $pks)$!pk.shortType $!pk.name#if($velocityCount != $pks.size()), #end#end);\n\n /**\n * 查询批量数据\n *\n * @param $!{queryInstanceName} 筛选条件\n * @return 查询结果\n */\n List<$!{entityClassName}> selectList($!{queryClassName} $!{queryInstanceName});\n\n /**\n * 查询总条数\n *\n * @param $!{queryInstanceName} 筛选条件\n * @return 总条数\n */\n long selectCount($!{queryClassName} $!{queryInstanceName});\n \n /**\n * 新增数据\n *\n * @param $!{entityInstanceName} 实例对象\n * @return 影响的行数\n */\n int save($!{entityClassName} $!{entityInstanceName});\n\n /**\n * 修改单条数据\n *\n * @param $!{entityInstanceName} 实例对象\n * @return 影响的行数\n */\n int update($!{entityClassName} $!{entityInstanceName});\n\n /**\n * 通过主键删除数据\n *\n#foreach($pk in $pks)\n * @param $!pk.name $!pk.comment\n#end\n * @return 影响的行数\n */\n int deleteByPrimaryKey(#foreach($pk in $pks)$!pk.shortType $!pk.name#if($velocityCount != $pks.size()), #end#end);\n\n}"
}, {
"name" : "baseServiceImpl.java.vm",
"code" : "##引入宏定义\n$!{define.vm}\n$!{daoDefine.vm}\n$!{globalValue.vm}\n\n##设置保存路径&文件名\n$!callback.setSavePath($!{baseServiceImplSavePath})\n$!callback.setFileName($!{baseServiceImplFileName})\n\n##包路径\n#if($baseServiceImplPackageName!=\"\")package #end$!baseServiceImplPackageName;\n\nimport $!{entityFullyClassName};\nimport $!{daoFullyClassName};\nimport $!{baseServiceFullyClassName};\nimport $!{queryFullyClassName};\nimport java.util.List;\nimport org.springframework.stereotype.Service;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport java.util.Objects;\n\n##使用宏定义实现类注释信息\n#tableComment(\"基础服务实现类\")\n@Service\npublic class $!{baseServiceImplClassName} implements $!{baseServiceClassName} {\n @Autowired\n private $!{daoClassName} $!{daoInstanceName};\n \n /**\n * 查询单条数据\n *\n#foreach($pk in $pks)\n * @param $!pk.name $!pk.comment\n#end\n * @return 实例对象\n */\n @Override\n public $!{entityClassName} selectByPrimaryKey(#foreach($pk in $pks)$!pk.shortType $!pk.name#if($velocityCount != $pks.size()), #end#end) {\n return $!{daoInstanceName}.$!{selectByPrimaryKey}(#foreach($pk in $pks)$!pk.name#if($velocityCount != $pks.size()), #end#end);\n }\n\n /**\n * 查询批量数据\n *\n * @param $!{queryInstanceName} 筛选条件\n * @return 查询结果\n */\n @Override\n public List<$!{entityClassName}> selectList($!{queryClassName} $!{queryInstanceName}) {\n if(Objects.equals($!{queryInstanceName}, new $!{queryClassName}())){\n throw new RuntimeException(\"selectSelective参数不能全为空,业务逻辑异常\");\n }\n return $!{daoInstanceName}.$!{selectSelective}($!{queryInstanceName});\n }\n\n @Override\n public long selectCount($!{queryClassName} $!{queryInstanceName}){\n return $!{daoInstanceName}.selectCount($!{queryInstanceName});\n }\n \n /**\n * 新增数据\n *\n * @param $!{entityInstanceName} 实例对象\n * @return 影响的行数\n */\n @Override\n public int save($!{entityClassName} $!{entityInstanceName}) {\n return $!{daoInstanceName}.$!{insertSelective}($!{entityInstanceName});\n }\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 影响的行数\n */\n @Override\n public int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {\n return $!{daoInstanceName}.$!{updateByPrimaryKeySelective}($!tool.firstLowerCase($!{tableInfo.name}));\n }\n\n /**\n * 通过主键删除数据\n *\n#foreach($pk in $pks)\n * @param $!pk.name $!pk.comment\n#end\n * @return 影响的行数\n */\n @Override\n public int deleteByPrimaryKey(#foreach($pk in $pks)$!pk.shortType $!pk.name#if($velocityCount != $pks.size()), #end#end) {\n return $!{daoInstanceName}.$!{deleteByPrimaryKey}(#foreach($pk in $pks)$!pk.name#if($velocityCount != $pks.size()), #end#end);\n }\n}"
}, {
"name" : "orderFieldEnum.java.vm",
"code" : "##引入宏定义\n$!{define.vm}\n$!{daoDefine.vm}\n$!{globalValue.vm}\n\n##设置保存路径&文件名\n$!callback.setSavePath($!{orderFieldEnumSavePath})\n$!callback.setFileName($!{orderFieldEnumFileName})\n\n##包路径\n#if($orderFieldEnumPackageName!=\"\")package #end$!orderFieldEnumPackageName;\n\n#tableComment(\"排序字段\")\npublic enum $!{orderFieldEnumClassName} {\n#foreach($column in $tableInfo.fullColumn)\n $column.obj.name#[[(]]#\"$column.name\", \"$column.obj.name\", \"$column.comment\"#[[)]]#,\n#end\n ;\n \n private final String value;\n private final String desc;\n private final String comment;\n\n public String value() {\n return this.value;\n }\n\n public String desc() {\n return this.desc;\n }\n\n public String comment() {\n return this.comment;\n }\n\n $!{orderFieldEnumClassName}(final String value, final String desc, final String comment) {\n this.value = value;\n this.desc = desc;\n this.comment = comment;\n }\n\n public static String getValue(String desc) {\n $!{orderFieldEnumClassName}[] $!{orderFieldEnumInstanceName}s = values();\n for ($!{orderFieldEnumClassName} $!{orderFieldEnumInstanceName} : $!{orderFieldEnumInstanceName}s) {\n if ($!{orderFieldEnumInstanceName}.desc.equals(desc)) {\n return $!{orderFieldEnumInstanceName}.value;\n }\n }\n return null;\n }\n\n public static String getDesc(String value) {\n $!{orderFieldEnumClassName}[] $!{orderFieldEnumInstanceName}s = values();\n for ($!{orderFieldEnumClassName} $!{orderFieldEnumInstanceName} : $!{orderFieldEnumInstanceName}s) {\n if ($!{orderFieldEnumInstanceName}.value.equals(value)) {\n return $!{orderFieldEnumInstanceName}.desc;\n }\n }\n return null;\n }\n\n}"
} ]
}
},
"columnConfig" : {
"Default" : {
"name" : "Default",
"elementList" : [ {
"title" : "disable",
"type" : "BOOLEAN",
"selectValue" : ""
}, {
"title" : "support",
"type" : "SELECT",
"selectValue" : "add,edit,query,del,ui"
} ]
}
},
"globalConfig" : {
"entWallet" : {
"name" : "entWallet",
"elementList" : [ {
"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##定义直接保存路径与文件名简化的宏定义,调用方式:#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##集合toString\n#macro(setToString $list $delimiter)\n #foreach($item in $list)$!item#if($velocityCount != $pks.size())$delimiter#end#end\n#end\n\n##定义表注释的宏定义,调用方式:#tableComment(\"注释信息\")\n#macro(tableComment $desc)\n/**\n * $!{tableInfo.comment}($!{tableInfo.name})$desc\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"
}, {
"name" : "daoDefine.vm",
"value" : "##Java文件根路径\n#set($javaFileRoot = \"/src/main/java\")\n##Mapper文件根路径\n#set($mapperFileRoot = \"/src/main/resources\")\n\n##Mapper配置\n##相对地址配置&文件名后缀\n#set($mapperRelativePath = \"/mapper\")\n#set($mapperNameSuffix = \"Mapper\")\n\n##mapper文件的几个基本属性名\n#set($BaseColumnList = \"Base_Column_List\")\n#set($BaseResultMap = \"BaseResultMap\")\n\n##dao配置\n##相对地址配置&文件名后缀\n#set($daoRelativePath = \"/com/cmb/fpy/ent/wallet/persist/dao\")\n#set($daoNameSuffix = \"Dao\")\n\n##dao层的六个方法\n#set($selectByPrimaryKey = \"selectByPrimaryKey\")\n#set($selectSelective = \"selectSelective\")\n#set($count = \"selectCount\")\n#set($insertSelective = \"insertSelective\")\n#set($updateByPrimaryKeySelective = \"updateByPrimaryKeySelective\")\n#set($deleteByPrimaryKey = \"deleteByPrimaryKey\")\n\n##entity配置\n##相对地址配置&文件名后缀\n#set($entityRelativePath = \"/com/cmb/fpy/ent/wallet/persist/entity\")\n\n##baseService配置\n##相对地址配置&文件名后缀\n#set($baseServiceRelativePath = \"/com/cmb/fpy/ent/wallet/service/base\")\n#set($baseServiceNameSuffix = \"BaseService\")\n\n##query配置\n##相对地址配置&文件名后缀\n#set($queryRelativePath = \"/com/cmb/fpy/ent/wallet/pojo/query\")\n#set($queryNameSuffix = \"Query\")\n\n##orderFieldEnum配置\n#set($orderFieldEnumRelativePath = \"/com/cmb/fpy/ent/wallet/constant/orderfield\")\n#set($orderFieldEnumNameSuffix = \"OrderFieldEnum\")\n\n##如果有自定义前缀,也可手动改成该属性\n#set($FullySchemaName = \"EWL.\")\n"
}, {
"name" : "globalValue.vm",
"value" : "##depencies daoDefine.vm\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pks = $tableInfo.pkColumn)\n#end\n\n##entity\n#set($entityClassName = $tool.append($tableInfo.name, \"\"))\n#set($entityInstanceName = $!tool.firstLowerCase($entityClassName))\n#set($entitySavePath = $tool.append($modulePath, $javaFileRoot, $!{entityRelativePath}))\n#set($entityFileName = $tool.append($tableInfo.name, \".java\"))\n#set($entityPackageName = $entityRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($entityFullyPathName = $tool.append($entitySavePath, \"/\", $entityFileName))\n#set($entityFullyClassName = $tool.append($entityPackageName, \".\", $entityClassName))\n\n##dao\n#set($daoClassName = $tool.append($tableInfo.name, $!{daoNameSuffix}))\n#set($daoInstanceName = $!tool.firstLowerCase($daoClassName))\n#set($daoSavePath = $tool.append($modulePath,$javaFileRoot, $!{daoRelativePath}))\n#set($daoFileName = $tool.append($daoClassName ,\".java\"))\n#set($daoPackageName = $daoRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($daoFullyPathName = $tool.append($daoSavePath, \"/\", $daoFileName))\n#set($daoFullyClassName = $tool.append($daoPackageName, \".\", $daoClassName))\n\n##query\n#set($queryClassName = $tool.append($tableInfo.name, $!{queryNameSuffix}))\n#set($queryInstanceName = $!tool.firstLowerCase($queryClassName))\n#set($querySavePath = $tool.append($modulePath,$javaFileRoot, $!{queryRelativePath}))\n#set($queryFileName = $tool.append($queryClassName,\".java\"))\n#set($queryPackageName = $queryRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($queryFullyPathName = $tool.append($querySavePath, \"/\", $queryFileName))\n#set($queryFullyClassName = $tool.append($queryPackageName, \".\", $queryClassName))\n\n##mapper\n#set($mapperClassName = $tool.append($tableInfo.name, $!{mapperNameSuffix}))\n#set($mapperInstanceName = $!tool.firstLowerCase($mapperClassName))\n#set($mapperSavePath = $tool.append($modulePath,$mapperFileRoot, $!{mapperRelativePath}))\n#set($mapperFileName = $tool.append($mapperClassName,\".xml\"))\n#set($mapperPackageName = $mapperRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($mapperFullyPathName = $tool.append($mapperSavePath, \"/\", $mapperFileName))\n#set($mapperFullyClassName = $tool.append($mapperPackageName, \".\", $mapperClassName))\n\n##baseService\n#set($baseServiceClassName = $tool.append($tableInfo.name, $!{baseServiceNameSuffix}))\n#set($baseServiceInstanceName = $!tool.firstLowerCase($baseServiceClassName))\n#set($baseServiceSavePath = $tool.append($modulePath,$javaFileRoot, $!{baseServiceRelativePath}))\n#set($baseServiceFileName = $tool.append($baseServiceClassName,\".java\"))\n#set($baseServicePackageName = $baseServiceRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($baseServiceFullyPathName = $tool.append($baseServiceSavePath, \"/\", $baseServiceFileName))\n#set($baseServiceFullyClassName = $tool.append($baseServicePackageName, \".\", $baseServiceClassName))\n\n##baseServiceImpl\n#set($baseServiceImplClassName = $tool.append($tableInfo.name, $!{baseServiceNameSuffix}, \"Impl\"))\n#set($baseServiceImplInstanceName = $!tool.firstLowerCase($baseServiceImplClassName))\n#set($baseServiceImplRelativePath = $tool.append($!{baseServiceRelativePath}, \"/impl\"))\n#set($baseServiceImplSavePath = $tool.append($modulePath,$javaFileRoot, $!{baseServiceImplRelativePath}))\n#set($baseServiceImplFileName = $tool.append($baseServiceImplClassName,\".java\"))\n#set($baseServiceImplPackageName = $baseServiceImplRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($baseServiceImplFullyPathName = $tool.append($baseServiceImplSavePath, \"/\", $baseServiceImplFileName))\n#set($baseServiceImplFullyClassName = $tool.append($baseServiceImplPackageName, \".\", $baseServiceImplClassName))\n\n##orderFieldEnum\n#set($orderFieldEnumClassName = $tool.append($tableInfo.name, $!{orderFieldEnumNameSuffix}))\n#set($orderFieldEnumInstanceName = $!tool.firstLowerCase($orderFieldEnumClassName))\n#set($orderFieldEnumSavePath = $tool.append($modulePath,$javaFileRoot, $!{orderFieldEnumRelativePath}))\n#set($orderFieldEnumFileName = $tool.append($orderFieldEnumClassName,\".java\"))\n#set($orderFieldEnumPackageName = $orderFieldEnumRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($orderFieldEnumFullyPathName = $tool.append($orderFieldEnumSavePath, \"/\", $orderFieldEnumFileName))\n#set($orderFieldEnumFullyClassName = $tool.append($orderFieldEnumPackageName, \".\", $orderFieldEnumClassName))"
}, {
"name" : "autoImport.vm",
"value" : "##自动导入包(仅导入实体属性需要的包,通常用于实体类)\n#foreach($import in $importList)\nimport $!import;\n#end"
} ]
},
"InvCollect" : {
"name" : "InvCollect",
"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##定义直接保存路径与文件名简化的宏定义,调用方式:#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##集合toString\n#macro(setToString $list $delimiter)\n #foreach($item in $list)$!item#if($velocityCount != $pks.size())$delimiter#end#end\n#end\n\n##定义表注释的宏定义,调用方式:#tableComment(\"注释信息\")\n#macro(tableComment $desc)\n/**\n * $!{tableInfo.comment}($!{tableInfo.name})$desc\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"
}, {
"name" : "daoDefine.vm",
"value" : "##Java文件根路径\n#set($javaFileRoot = \"/src/main/java\")\n##Mapper文件根路径\n#set($mapperFileRoot = \"/src/main/resources\")\n\n##Mapper配置\n##相对地址配置&文件名后缀\n#set($mapperRelativePath = \"/mapper\")\n#set($mapperNameSuffix = \"Mapper\")\n\n##mapper文件的几个基本属性名\n#set($BaseColumnList = \"Base_Column_List\")\n#set($BaseResultMap = \"BaseResultMap\")\n\n##dao配置\n##相对地址配置&文件名后缀\n#set($daoRelativePath = \"/com/cmb/fpy/inv/collect/persist/dao\")\n#set($daoNameSuffix = \"Dao\")\n\n##dao层的六个方法\n#set($selectByPrimaryKey = \"selectByPrimaryKey\")\n#set($selectSelective = \"selectSelective\")\n#set($count = \"selectCount\")\n#set($insertSelective = \"insertSelective\")\n#set($updateByPrimaryKeySelective = \"updateByPrimaryKeySelective\")\n#set($deleteByPrimaryKey = \"deleteByPrimaryKey\")\n\n##entity配置\n##相对地址配置&文件名后缀\n#set($entityRelativePath = \"/com/cmb/fpy/inv/collect/persist/entity\")\n\n##baseService配置\n##相对地址配置&文件名后缀\n#set($baseServiceRelativePath = \"/com/cmb/fpy/inv/collect/service/base\")\n#set($baseServiceNameSuffix = \"BaseService\")\n\n##query配置\n##相对地址配置&文件名后缀\n#set($queryRelativePath = \"/com/cmb/fpy/inv/collect/pojo/query\")\n#set($queryNameSuffix = \"Query\")\n\n##orderFieldEnum配置\n#set($orderFieldEnumRelativePath = \"/com/cmb/fpy/inv/collect/constant/orderfield\")\n#set($orderFieldEnumNameSuffix = \"OrderFieldEnum\")\n\n##如果有自定义前缀,也可手动改成该属性\n#set($FullySchemaName = \"invcolle.\")\n"
}, {
"name" : "globalValue.vm",
"value" : "##depencies daoDefine.vm\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pks = $tableInfo.pkColumn)\n#end\n\n##entity\n#set($entityClassName = $tool.append($tableInfo.name, \"\"))\n#set($entityInstanceName = $!tool.firstLowerCase($entityClassName))\n#set($entitySavePath = $tool.append($modulePath, $javaFileRoot, $!{entityRelativePath}))\n#set($entityFileName = $tool.append($tableInfo.name, \".java\"))\n#set($entityPackageName = $entityRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($entityFullyPathName = $tool.append($entitySavePath, \"/\", $entityFileName))\n#set($entityFullyClassName = $tool.append($entityPackageName, \".\", $entityClassName))\n\n##dao\n#set($daoClassName = $tool.append($tableInfo.name, $!{daoNameSuffix}))\n#set($daoInstanceName = $!tool.firstLowerCase($daoClassName))\n#set($daoSavePath = $tool.append($modulePath,$javaFileRoot, $!{daoRelativePath}))\n#set($daoFileName = $tool.append($daoClassName ,\".java\"))\n#set($daoPackageName = $daoRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($daoFullyPathName = $tool.append($daoSavePath, \"/\", $daoFileName))\n#set($daoFullyClassName = $tool.append($daoPackageName, \".\", $daoClassName))\n\n##query\n#set($queryClassName = $tool.append($tableInfo.name, $!{queryNameSuffix}))\n#set($queryInstanceName = $!tool.firstLowerCase($queryClassName))\n#set($querySavePath = $tool.append($modulePath,$javaFileRoot, $!{queryRelativePath}))\n#set($queryFileName = $tool.append($queryClassName,\".java\"))\n#set($queryPackageName = $queryRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($queryFullyPathName = $tool.append($querySavePath, \"/\", $queryFileName))\n#set($queryFullyClassName = $tool.append($queryPackageName, \".\", $queryClassName))\n\n##mapper\n#set($mapperClassName = $tool.append($tableInfo.name, $!{mapperNameSuffix}))\n#set($mapperInstanceName = $!tool.firstLowerCase($mapperClassName))\n#set($mapperSavePath = $tool.append($modulePath,$mapperFileRoot, $!{mapperRelativePath}))\n#set($mapperFileName = $tool.append($mapperClassName,\".xml\"))\n#set($mapperPackageName = $mapperRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($mapperFullyPathName = $tool.append($mapperSavePath, \"/\", $mapperFileName))\n#set($mapperFullyClassName = $tool.append($mapperPackageName, \".\", $mapperClassName))\n\n##baseService\n#set($baseServiceClassName = $tool.append($tableInfo.name, $!{baseServiceNameSuffix}))\n#set($baseServiceInstanceName = $!tool.firstLowerCase($baseServiceClassName))\n#set($baseServiceSavePath = $tool.append($modulePath,$javaFileRoot, $!{baseServiceRelativePath}))\n#set($baseServiceFileName = $tool.append($baseServiceClassName,\".java\"))\n#set($baseServicePackageName = $baseServiceRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($baseServiceFullyPathName = $tool.append($baseServiceSavePath, \"/\", $baseServiceFileName))\n#set($baseServiceFullyClassName = $tool.append($baseServicePackageName, \".\", $baseServiceClassName))\n\n##baseServiceImpl\n#set($baseServiceImplClassName = $tool.append($tableInfo.name, $!{baseServiceNameSuffix}, \"Impl\"))\n#set($baseServiceImplInstanceName = $!tool.firstLowerCase($baseServiceImplClassName))\n#set($baseServiceImplRelativePath = $tool.append($!{baseServiceRelativePath}, \"/impl\"))\n#set($baseServiceImplSavePath = $tool.append($modulePath,$javaFileRoot, $!{baseServiceImplRelativePath}))\n#set($baseServiceImplFileName = $tool.append($baseServiceImplClassName,\".java\"))\n#set($baseServiceImplPackageName = $baseServiceImplRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($baseServiceImplFullyPathName = $tool.append($baseServiceImplSavePath, \"/\", $baseServiceImplFileName))\n#set($baseServiceImplFullyClassName = $tool.append($baseServiceImplPackageName, \".\", $baseServiceImplClassName))\n\n##orderFieldEnum\n#set($orderFieldEnumClassName = $tool.append($tableInfo.name, $!{orderFieldEnumNameSuffix}))\n#set($orderFieldEnumInstanceName = $!tool.firstLowerCase($orderFieldEnumClassName))\n#set($orderFieldEnumSavePath = $tool.append($modulePath,$javaFileRoot, $!{orderFieldEnumRelativePath}))\n#set($orderFieldEnumFileName = $tool.append($orderFieldEnumClassName,\".java\"))\n#set($orderFieldEnumPackageName = $orderFieldEnumRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($orderFieldEnumFullyPathName = $tool.append($orderFieldEnumSavePath, \"/\", $orderFieldEnumFileName))\n#set($orderFieldEnumFullyClassName = $tool.append($orderFieldEnumPackageName, \".\", $orderFieldEnumClassName))"
} ]
},
"Default" : {
"name" : "Default",
"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##定义直接保存路径与文件名简化的宏定义,调用方式:#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##集合toString\n#macro(setToString $list $delimiter)\n #foreach($item in $list)$!item#if($velocityCount != $pks.size())$delimiter#end#end\n#end\n\n##定义表注释的宏定义,调用方式:#tableComment(\"注释信息\")\n#macro(tableComment $desc)\n/**\n * $!{tableInfo.comment}($!{tableInfo.name})$desc\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"
}, {
"name" : "daoDefine.vm",
"value" : "##Java文件根路径\n#set($javaFileRoot = \"/src/main/java\")\n##Mapper文件根路径\n#set($mapperFileRoot = \"/src/main/resources\")\n\n##Mapper配置\n##相对地址配置&文件名后缀\n#set($mapperRelativePath = \"/mapper\")\n#set($mapperNameSuffix = \"Mapper\")\n\n##mapper文件的几个基本属性名\n#set($BaseColumnList = \"Base_Column_List\")\n#set($BaseResultMap = \"BaseResultMap\")\n\n##dao配置\n##相对地址配置&文件名后缀\n#set($daoRelativePath = \"/com/cmb/fpy/inv/collect/persist/dao\")\n#set($daoNameSuffix = \"Dao\")\n\n##dao层的六个方法\n#set($selectByPrimaryKey = \"selectByPrimaryKey\")\n#set($selectSelective = \"selectSelective\")\n#set($count = \"selectCount\")\n#set($insertSelective = \"insertSelective\")\n#set($updateByPrimaryKeySelective = \"updateByPrimaryKeySelective\")\n#set($deleteByPrimaryKey = \"deleteByPrimaryKey\")\n\n##entity配置\n##相对地址配置&文件名后缀\n#set($entityRelativePath = \"/com/cmb/fpy/inv/collect/persist/entity\")\n\n##baseService配置\n##相对地址配置&文件名后缀\n#set($baseServiceRelativePath = \"/com/cmb/fpy/inv/collect/service/base\")\n#set($baseServiceNameSuffix = \"BaseService\")\n\n##query配置\n##相对地址配置&文件名后缀\n#set($queryRelativePath = \"/com/cmb/fpy/inv/collect/pojo/query\")\n#set($queryNameSuffix = \"Query\")\n\n##orderFieldEnum配置\n#set($orderFieldEnumRelativePath = \"/com/cmb/fpy/inv/collect/constant/orderfield\")\n#set($orderFieldEnumNameSuffix = \"OrderFieldEnum\")\n\n##如果有自定义前缀,也可手动改成该属性\n#set($FullySchemaName = \"invcolle.\")\n"
}, {
"name" : "globalValue.vm",
"value" : "##depencies daoDefine.vm\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pks = $tableInfo.pkColumn)\n#end\n\n##entity\n#set($entityClassName = $tool.append($tableInfo.name, \"\"))\n#set($entityInstanceName = $!tool.firstLowerCase($entityClassName))\n#set($entitySavePath = $tool.append($modulePath, $javaFileRoot, $!{entityRelativePath}))\n#set($entityFileName = $tool.append($tableInfo.name, \".java\"))\n#set($entityPackageName = $entityRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($entityFullyPathName = $tool.append($entitySavePath, \"/\", $entityFileName))\n#set($entityFullyClassName = $tool.append($entityPackageName, \".\", $entityClassName))\n\n##dao\n#set($daoClassName = $tool.append($tableInfo.name, $!{daoNameSuffix}))\n#set($daoInstanceName = $!tool.firstLowerCase($daoClassName))\n#set($daoSavePath = $tool.append($modulePath,$javaFileRoot, $!{daoRelativePath}))\n#set($daoFileName = $tool.append($daoClassName ,\".java\"))\n#set($daoPackageName = $daoRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($daoFullyPathName = $tool.append($daoSavePath, \"/\", $daoFileName))\n#set($daoFullyClassName = $tool.append($daoPackageName, \".\", $daoClassName))\n\n##query\n#set($queryClassName = $tool.append($tableInfo.name, $!{queryNameSuffix}))\n#set($queryInstanceName = $!tool.firstLowerCase($queryClassName))\n#set($querySavePath = $tool.append($modulePath,$javaFileRoot, $!{queryRelativePath}))\n#set($queryFileName = $tool.append($queryClassName,\".java\"))\n#set($queryPackageName = $queryRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($queryFullyPathName = $tool.append($querySavePath, \"/\", $queryFileName))\n#set($queryFullyClassName = $tool.append($queryPackageName, \".\", $queryClassName))\n\n##mapper\n#set($mapperClassName = $tool.append($tableInfo.name, $!{mapperNameSuffix}))\n#set($mapperInstanceName = $!tool.firstLowerCase($mapperClassName))\n#set($mapperSavePath = $tool.append($modulePath,$mapperFileRoot, $!{mapperRelativePath}))\n#set($mapperFileName = $tool.append($mapperClassName,\".xml\"))\n#set($mapperPackageName = $mapperRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($mapperFullyPathName = $tool.append($mapperSavePath, \"/\", $mapperFileName))\n#set($mapperFullyClassName = $tool.append($mapperPackageName, \".\", $mapperClassName))\n\n##baseService\n#set($baseServiceClassName = $tool.append($tableInfo.name, $!{baseServiceNameSuffix}))\n#set($baseServiceInstanceName = $!tool.firstLowerCase($baseServiceClassName))\n#set($baseServiceSavePath = $tool.append($modulePath,$javaFileRoot, $!{baseServiceRelativePath}))\n#set($baseServiceFileName = $tool.append($baseServiceClassName,\".java\"))\n#set($baseServicePackageName = $baseServiceRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($baseServiceFullyPathName = $tool.append($baseServiceSavePath, \"/\", $baseServiceFileName))\n#set($baseServiceFullyClassName = $tool.append($baseServicePackageName, \".\", $baseServiceClassName))\n\n##baseServiceImpl\n#set($baseServiceImplClassName = $tool.append($tableInfo.name, $!{baseServiceNameSuffix}, \"Impl\"))\n#set($baseServiceImplInstanceName = $!tool.firstLowerCase($baseServiceImplClassName))\n#set($baseServiceImplRelativePath = $tool.append($!{baseServiceRelativePath}, \"/impl\"))\n#set($baseServiceImplSavePath = $tool.append($modulePath,$javaFileRoot, $!{baseServiceImplRelativePath}))\n#set($baseServiceImplFileName = $tool.append($baseServiceImplClassName,\".java\"))\n#set($baseServiceImplPackageName = $baseServiceImplRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($baseServiceImplFullyPathName = $tool.append($baseServiceImplSavePath, \"/\", $baseServiceImplFileName))\n#set($baseServiceImplFullyClassName = $tool.append($baseServiceImplPackageName, \".\", $baseServiceImplClassName))\n\n##orderFieldEnum\n#set($orderFieldEnumClassName = $tool.append($tableInfo.name, $!{orderFieldEnumNameSuffix}))\n#set($orderFieldEnumInstanceName = $!tool.firstLowerCase($orderFieldEnumClassName))\n#set($orderFieldEnumSavePath = $tool.append($modulePath,$javaFileRoot, $!{orderFieldEnumRelativePath}))\n#set($orderFieldEnumFileName = $tool.append($orderFieldEnumClassName,\".java\"))\n#set($orderFieldEnumPackageName = $orderFieldEnumRelativePath.replaceAll(\"/\",\".\").substring(1))\n#set($orderFieldEnumFullyPathName = $tool.append($orderFieldEnumSavePath, \"/\", $orderFieldEnumFileName))\n#set($orderFieldEnumFullyClassName = $tool.append($orderFieldEnumPackageName, \".\", $orderFieldEnumClassName))"
} ]
}
}
}
如需应用我的easyCode配置,复制上述配置,然后找到路径:File-Setting-Other Settings-EasyCode,选择从剪切板导入即可。
easyCode的基本原理是:
1、先从数据库读取表的参数,包括表名、字段名、字段类型,从而生成表对象和列对象等等。
2、在用户自定义的模板中,可引用这些表对象和列对象的属性。
3、生成代码时,easyCode会把相应的值填充到引用中,类似于占位符的填充。
为了读取数据库,需要配置Database,配置方法在上面的easyCode安装和使用教程已经说明了。
easyCode本身并不复杂,自带的使用说明也是清晰易懂,但要使用好需要潜下心去研究,相比于学习前两点技巧可能需要花费更多的时间,但是它是值得的。有几点好处:
1、显著节省开发时间
2、避免犯低级错误(比如某个字段名搞错了或者没写)
3、规范性、可读性、可扩展性好
以上是idea开发提高效率的技巧篇,希望能够对大家的工作效率提高有所帮助,不足之处也请指正。然而很多时候开发慢并不是因为工具不够好导致的,而是旧的代码复用性、扩展性太差导致的,后续会专门出一系列讲如何提高代码复用率和扩展性的,包括:
1、如何封装函数
2、如何设计类的继承结构
3、如何设计切面
敬请期待~
-------------------------------------------------------分割符-----------------------------------------------------
如何封装函数 20220829更新