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:
@@ -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>
|
||||
Reference in New Issue
Block a user