mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2025-12-26 05:48:33 +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:
parent
65f79b751f
commit
0b84f272b8
@ -16,6 +16,7 @@ SpringBootCodeGenerator
|
||||
<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>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>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>
|
||||
@ -40,10 +41,13 @@ SpringBootCodeGenerator
|
||||
</tbody></table>
|
||||
|
||||
<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>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>fieldComment</td> <td>字段备注</td></tr>
|
||||
</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}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Component
|
||||
@Repository
|
||||
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
|
||||
* @param offset
|
||||
* @param pageSize
|
||||
*/
|
||||
public List<${classInfo.className}> pageList(@Param("offset") int offset,
|
||||
@Param("pagesize") int pagesize);
|
||||
public List<${classInfo.className}Entity> pageList(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);
|
||||
|
||||
/**
|
||||
* 分页查询Count
|
||||
*/
|
||||
public int pageListCount(@Param("offset") int offset,
|
||||
@Param("pagesize") int pagesize);
|
||||
public Integer pageListCount();
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,80 +3,87 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="${packageName}.dao.${classInfo.className}Dao">
|
||||
|
||||
<resultMap id="${classInfo.className}" type="${packageName}.entity.${classInfo.className}" >
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<result column="${fieldItem.columnName}" property="${fieldItem.fieldName}" />
|
||||
</#list>
|
||||
</#if>
|
||||
<resultMap id="BaseResultMap" type="${packageName}.entity.${classInfo.className}Entity" >
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<result column="${fieldItem.columnName}" property="${fieldItem.fieldName}" />
|
||||
</#list>
|
||||
</#if>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
`${fieldItem.columnName}`<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
`${fieldItem.columnName}`<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="java.util.Map" >
|
||||
INSERT INTO ${classInfo.tableName} (
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "Id" >
|
||||
`${fieldItem.columnName}`<#if fieldItem_has_next>,</#if>
|
||||
<insert id="insert" useGeneratedKeys="true" keyColumn="id" parameterType="${packageName}.entity.${classInfo.className}Entity">
|
||||
INSERT INTO ${classInfo.tableName}
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "id_" >
|
||||
${r"<if test ='null != "}${fieldItem.fieldName}${r"'>"}
|
||||
`${fieldItem.columnName}`<#if fieldItem_has_next>,</#if>
|
||||
${r"</if>"}
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
)
|
||||
VALUES(
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "Id" >
|
||||
<#if fieldItem.columnName="addtime" || fieldItem.columnName="updatetime" >
|
||||
NOW()<#if fieldItem_has_next>,</#if>
|
||||
<#else>
|
||||
${r"#{"}${classInfo.className?uncap_first}.${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "id_" >
|
||||
<#--<#if fieldItem.columnName="addtime" || fieldItem.columnName="updatetime" >
|
||||
${r"<if test ='null != "}${fieldItem.fieldName}${r"'>"}
|
||||
NOW()<#if fieldItem_has_next>,</#if>
|
||||
${r"</if>"}
|
||||
<#else>-->
|
||||
${r"<if test ='null != "}${fieldItem.fieldName}${r"'>"}
|
||||
${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>
|
||||
${r"</if>"}
|
||||
<#--</#if>-->
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
)
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<delete id="delete" parameterType="java.util.Map" >
|
||||
<delete id="delete" >
|
||||
DELETE FROM ${classInfo.tableName}
|
||||
WHERE `id` = ${r"#{id}"}
|
||||
WHERE `id_` = ${r"#{id}"}
|
||||
</delete>
|
||||
|
||||
<update id="update" parameterType="java.util.Map" >
|
||||
<update id="update" parameterType="${packageName}.entity.${classInfo.className}Entity">
|
||||
UPDATE ${classInfo.tableName}
|
||||
SET
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "Id" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime" >
|
||||
${fieldItem.columnName} = ${r"#{"}${classInfo.className?uncap_first}.${fieldItem.fieldName}${r"}"},
|
||||
</#if>
|
||||
</#list>
|
||||
UpdateTime = NOW()
|
||||
WHERE `id` = ${r"#{"}${classInfo.className?uncap_first}.id${r"}"}
|
||||
<set>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.columnName != "id_" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime" >
|
||||
${r"<if test ='null != "}${fieldItem.fieldName}${r"'>"}${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>${r"</if>"}
|
||||
</#if>
|
||||
</#list>
|
||||
</set>
|
||||
WHERE `id_` = ${r"#{"}id${r"}"}
|
||||
</update>
|
||||
|
||||
|
||||
<select id="load" parameterType="java.util.Map" resultMap="${classInfo.className}">
|
||||
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM ${classInfo.tableName}
|
||||
WHERE `id` = ${r"#{id}"}
|
||||
WHERE `id_` = ${r"#{id}"}
|
||||
</select>
|
||||
|
||||
<select id="pageList" parameterType="java.util.Map" resultMap="${classInfo.className}">
|
||||
<select id="pageList" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM ${classInfo.tableName}
|
||||
LIMIT ${r"#{offset}"}, ${r"#{pagesize}"}
|
||||
LIMIT ${r"#{offset}"}, ${r"#{pageSize}"}
|
||||
</select>
|
||||
|
||||
<select id="pageListCount" parameterType="java.util.Map" resultType="int">
|
||||
<select id="pageListCount" resultType="java.lang.Integer">
|
||||
SELECT count(1)
|
||||
FROM ${classInfo.tableName}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
Loading…
x
Reference in New Issue
Block a user