mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2026-03-22 15:39:04 +08:00
优化mybatis模块的dao和xml模板,修改dao接口注解为@Repository,所有dao参数改为包装类,删除update语句最后的UpdateTime = NOW(),修改dao接口文件的方法注释使其更符合javaDoc的标准,修改insert语句增加插入行主键的返回,修改load的方法名为selectByPrimaryKey,修改xml的update语句新增动态if判空,修改xml的insert语句新增动态插入判空,更符合mybatisGenerator标准(感谢@Archer-Wen的贡献 )
This commit is contained in:
@@ -16,6 +16,7 @@ SpringBootCodeGenerator
|
|||||||
<tr><td>CSDN博客</td> <td>http://blog.csdn.net/moshowgame</td></tr>
|
<tr><td>CSDN博客</td> <td>http://blog.csdn.net/moshowgame</td></tr>
|
||||||
<tr><td></td> <td></td></tr>
|
<tr><td></td> <td></td></tr>
|
||||||
<tr><td>更新日期</td> <td>更新内容</td></tr>
|
<tr><td>更新日期</td> <td>更新内容</td></tr>
|
||||||
|
<tr><td>20190511<td>优化mybatis模块的dao和xml模板,修改dao接口注解为@Repository,所有dao参数改为包装类,删除update语句最后的UpdateTime = NOW(),修改dao接口文件的方法注释使其更符合javaDoc的标准,修改insert语句增加插入行主键的返回,修改load的方法名为selectByPrimaryKey,修改xml的update语句新增动态if判空,修改xml的insert语句新增动态插入判空,更符合mybatisGenerator标准(感谢@Archer-Wen的贡献 )。</td></tr>
|
||||||
<tr><td>20190429<td>新增返回封装工具类设置,优化对oracle注释comment on column的支持(感谢@liukex反馈),优化对普通和特殊storage关键字的判断(感谢@AhHeadFloating的反馈 )。</td></tr>
|
<tr><td>20190429<td>新增返回封装工具类设置,优化对oracle注释comment on column的支持(感谢@liukex反馈),优化对普通和特殊storage关键字的判断(感谢@AhHeadFloating的反馈 )。</td></tr>
|
||||||
<tr><td>20190211<td>提交gitignore,解决StringUtils.lowerCaseFirst潜在的NPE异常,校验修改为@RequestParam参数校验,lombok之@Data和@Slf4j优化,fix JdbcDAO模板类名显示为中文问题,WebMvcConfig整合MessageConverter,模板代码分类(感谢@liutf和@tfgzs的pull request)。</td></tr>
|
<tr><td>20190211<td>提交gitignore,解决StringUtils.lowerCaseFirst潜在的NPE异常,校验修改为@RequestParam参数校验,lombok之@Data和@Slf4j优化,fix JdbcDAO模板类名显示为中文问题,WebMvcConfig整合MessageConverter,模板代码分类(感谢@liutf和@tfgzs的pull request)。</td></tr>
|
||||||
<tr><td>20190210<td>实体生成规则切换为包装类型,不再采用基本数据类型,为实体类生成添加显示的默认构造方法(感谢@h2so的pull request)。</td></tr>
|
<tr><td>20190210<td>实体生成规则切换为包装类型,不再采用基本数据类型,为实体类生成添加显示的默认构造方法(感谢@h2so的pull request)。</td></tr>
|
||||||
@@ -40,10 +41,13 @@ SpringBootCodeGenerator
|
|||||||
</tbody></table>
|
</tbody></table>
|
||||||
|
|
||||||
<table><tbody>
|
<table><tbody>
|
||||||
<tr><td>类名</td> <td>说明</td></tr>
|
<tr><td>字段名</td> <td>说明</td></tr>
|
||||||
|
<tr><td>packageName</td> <td>自定义的包名</td></tr>
|
||||||
|
<tr><td>authorName</td> <td>自定义的作者名</td></tr>
|
||||||
|
<tr><td>returnUtil</td> <td>自定义的返回Util</td></tr>
|
||||||
<tr><td>tableName</td> <td>sql中的表名</td></tr>
|
<tr><td>tableName</td> <td>sql中的表名</td></tr>
|
||||||
<tr><td>className</td> <td>java类名</td></tr>
|
<tr><td>className</td> <td>java类名</td></tr>
|
||||||
<tr><td>classComment</td> <td>java类备注</td></tr>
|
<tr><td>classComment</td> <td>sql表备注/java类备注</td></tr>
|
||||||
<tr><td>fieldName</td> <td>字段名</td></tr>
|
<tr><td>fieldName</td> <td>字段名</td></tr>
|
||||||
<tr><td>fieldComment</td> <td>字段备注</td></tr>
|
<tr><td>fieldComment</td> <td>字段备注</td></tr>
|
||||||
</tbody></table>
|
</tbody></table>
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 183 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 129 KiB |
@@ -7,39 +7,43 @@ import java.util.List;
|
|||||||
* ${classInfo.classComment}
|
* ${classInfo.classComment}
|
||||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||||
*/
|
*/
|
||||||
@Component
|
@Repository
|
||||||
public interface ${classInfo.className}Dao {
|
public interface ${classInfo.className}Dao {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增
|
* 新增
|
||||||
|
* @param ${classInfo.className}Entity
|
||||||
*/
|
*/
|
||||||
public int insert(@Param("${classInfo.className?uncap_first}") ${classInfo.className} ${classInfo.className?uncap_first});
|
public Integer insert(@Param("${classInfo.className?uncap_first}") ${classInfo.className}Entity ${classInfo.className?uncap_first});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
|
* @param id
|
||||||
*/
|
*/
|
||||||
public int delete(@Param("id") int id);
|
public Integer delete(@Param("id") Integer id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新
|
* 更新
|
||||||
|
* @param ${classInfo.className}Entity
|
||||||
*/
|
*/
|
||||||
public int update(@Param("${classInfo.className?uncap_first}") ${classInfo.className} ${classInfo.className?uncap_first});
|
public Integer update(@Param("${classInfo.className?uncap_first}") ${classInfo.className}Entity ${classInfo.className?uncap_first});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load查询
|
* 根据主键查询一个实体
|
||||||
|
* @param id
|
||||||
*/
|
*/
|
||||||
public ${classInfo.className} load(@Param("id") int id);
|
public ${classInfo.className}Entity selectByPrimaryKey(@Param("id") Integer id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询Data
|
* 分页查询Data
|
||||||
|
* @param offset
|
||||||
|
* @param pageSize
|
||||||
*/
|
*/
|
||||||
public List<${classInfo.className}> pageList(@Param("offset") int offset,
|
public List<${classInfo.className}Entity> pageList(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);
|
||||||
@Param("pagesize") int pagesize);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询Count
|
* 分页查询Count
|
||||||
*/
|
*/
|
||||||
public int pageListCount(@Param("offset") int offset,
|
public Integer pageListCount();
|
||||||
@Param("pagesize") int pagesize);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,78 +3,85 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="${packageName}.dao.${classInfo.className}Dao">
|
<mapper namespace="${packageName}.dao.${classInfo.className}Dao">
|
||||||
|
|
||||||
<resultMap id="${classInfo.className}" type="${packageName}.entity.${classInfo.className}" >
|
<resultMap id="BaseResultMap" type="${packageName}.entity.${classInfo.className}Entity" >
|
||||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||||
<#list classInfo.fieldList as fieldItem >
|
<#list classInfo.fieldList as fieldItem >
|
||||||
<result column="${fieldItem.columnName}" property="${fieldItem.fieldName}" />
|
<result column="${fieldItem.columnName}" property="${fieldItem.fieldName}" />
|
||||||
</#list>
|
</#list>
|
||||||
</#if>
|
</#if>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||||
<#list classInfo.fieldList as fieldItem >
|
<#list classInfo.fieldList as fieldItem >
|
||||||
`${fieldItem.columnName}`<#if fieldItem_has_next>,</#if>
|
`${fieldItem.columnName}`<#if fieldItem_has_next>,</#if>
|
||||||
</#list>
|
</#list>
|
||||||
</#if>
|
</#if>
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<insert id="insert" parameterType="java.util.Map" >
|
<insert id="insert" useGeneratedKeys="true" keyColumn="id" parameterType="${packageName}.entity.${classInfo.className}Entity">
|
||||||
INSERT INTO ${classInfo.tableName} (
|
INSERT INTO ${classInfo.tableName}
|
||||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<#list classInfo.fieldList as fieldItem >
|
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||||
<#if fieldItem.columnName != "Id" >
|
<#list classInfo.fieldList as fieldItem >
|
||||||
`${fieldItem.columnName}`<#if fieldItem_has_next>,</#if>
|
<#if fieldItem.columnName != "id_" >
|
||||||
|
${r"<if test ='null != "}${fieldItem.fieldName}${r"'>"}
|
||||||
|
`${fieldItem.columnName}`<#if fieldItem_has_next>,</#if>
|
||||||
|
${r"</if>"}
|
||||||
|
</#if>
|
||||||
|
</#list>
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</trim>
|
||||||
</#if>
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
)
|
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||||
VALUES(
|
<#list classInfo.fieldList as fieldItem >
|
||||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
<#if fieldItem.columnName != "id_" >
|
||||||
<#list classInfo.fieldList as fieldItem >
|
<#--<#if fieldItem.columnName="addtime" || fieldItem.columnName="updatetime" >
|
||||||
<#if fieldItem.columnName != "Id" >
|
${r"<if test ='null != "}${fieldItem.fieldName}${r"'>"}
|
||||||
<#if fieldItem.columnName="addtime" || fieldItem.columnName="updatetime" >
|
NOW()<#if fieldItem_has_next>,</#if>
|
||||||
NOW()<#if fieldItem_has_next>,</#if>
|
${r"</if>"}
|
||||||
<#else>
|
<#else>-->
|
||||||
${r"#{"}${classInfo.className?uncap_first}.${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>
|
${r"<if test ='null != "}${fieldItem.fieldName}${r"'>"}
|
||||||
|
${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>
|
||||||
|
${r"</if>"}
|
||||||
|
<#--</#if>-->
|
||||||
|
</#if>
|
||||||
|
</#list>
|
||||||
</#if>
|
</#if>
|
||||||
</#if>
|
</trim>
|
||||||
</#list>
|
|
||||||
</#if>
|
|
||||||
)
|
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<delete id="delete" parameterType="java.util.Map" >
|
<delete id="delete" >
|
||||||
DELETE FROM ${classInfo.tableName}
|
DELETE FROM ${classInfo.tableName}
|
||||||
WHERE `id` = ${r"#{id}"}
|
WHERE `id_` = ${r"#{id}"}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<update id="update" parameterType="java.util.Map" >
|
<update id="update" parameterType="${packageName}.entity.${classInfo.className}Entity">
|
||||||
UPDATE ${classInfo.tableName}
|
UPDATE ${classInfo.tableName}
|
||||||
SET
|
<set>
|
||||||
<#list classInfo.fieldList as fieldItem >
|
<#list classInfo.fieldList as fieldItem >
|
||||||
<#if fieldItem.columnName != "Id" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime" >
|
<#if fieldItem.columnName != "id_" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime" >
|
||||||
${fieldItem.columnName} = ${r"#{"}${classInfo.className?uncap_first}.${fieldItem.fieldName}${r"}"},
|
${r"<if test ='null != "}${fieldItem.fieldName}${r"'>"}${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>${r"</if>"}
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
UpdateTime = NOW()
|
</set>
|
||||||
WHERE `id` = ${r"#{"}${classInfo.className?uncap_first}.id${r"}"}
|
WHERE `id_` = ${r"#{"}id${r"}"}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
<select id="load" parameterType="java.util.Map" resultMap="${classInfo.className}">
|
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
|
||||||
SELECT <include refid="Base_Column_List" />
|
SELECT <include refid="Base_Column_List" />
|
||||||
FROM ${classInfo.tableName}
|
FROM ${classInfo.tableName}
|
||||||
WHERE `id` = ${r"#{id}"}
|
WHERE `id_` = ${r"#{id}"}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="pageList" parameterType="java.util.Map" resultMap="${classInfo.className}">
|
<select id="pageList" resultMap="BaseResultMap">
|
||||||
SELECT <include refid="Base_Column_List" />
|
SELECT <include refid="Base_Column_List" />
|
||||||
FROM ${classInfo.tableName}
|
FROM ${classInfo.tableName}
|
||||||
LIMIT ${r"#{offset}"}, ${r"#{pagesize}"}
|
LIMIT ${r"#{offset}"}, ${r"#{pageSize}"}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="pageListCount" parameterType="java.util.Map" resultType="int">
|
<select id="pageListCount" resultType="java.lang.Integer">
|
||||||
SELECT count(1)
|
SELECT count(1)
|
||||||
FROM ${classInfo.tableName}
|
FROM ${classInfo.tableName}
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Reference in New Issue
Block a user