code-factory/src/main/resources/template/normal/mapper/mysql-mapper.ftl

346 lines
11 KiB
Plaintext
Raw Normal View History

2021-03-11 16:47:30 +08:00
<?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="${codePackage}.dao.${lowerTableName}.I${firstUpperTableName}Dao">
<resultMap id="${firstLowerTableName}DTO" type="${codePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO">
<#list fieldList! as field>
2021-03-15 22:22:49 +08:00
<#if field.listShow>
2021-03-11 16:47:30 +08:00
<result column="${field.columnName}" property="${field.propertyName}"/>
2021-03-15 22:22:49 +08:00
</#if>
2021-03-11 16:47:30 +08:00
</#list>
</resultMap>
<resultMap id="${firstLowerTableName}BO" type="${codePackage}.pojo.bos.${lowerTableName}.${firstUpperTableName}BO">
<#list fieldList! as field>
<result column="${field.columnName}" property="${field.propertyName}"/>
</#list>
</resultMap>
<resultMap id="${firstLowerTableName}PO" type="${codePackage}.pojo.pos.${lowerTableName}.${firstUpperTableName}PO">
<#list fieldList! as field>
<result column="${field.columnName}" property="${field.propertyName}"/>
</#list>
</resultMap>
<!-- 新增${tableExplain} -->
<insert id="save" parameterType="map">
INSERT INTO ${tableFullName}(
<#list fieldList! as field>
${field.columnName}${field.fieldSplit}
</#list>
) VALUES(
<#list fieldList! as field>
${r"#{"}${field.propertyName}${r"}"}${field.fieldSplit}
</#list>
)
</insert>
<#if hasIsDelete>
<!-- 删除${tableExplain} -->
<update id="remove" parameterType="map">
UPDATE
${tableFullName}
SET
<#if hasGmtModified>
gmt_modified = ${r"#{gmtModified}"},
</#if>
<#if hasModifier>
modifier = ${r"#{modifier}"},
</#if>
is_delete = 1
WHERE
<#if hasId>
2021-11-01 15:15:33 +08:00
${idColumn} IN
2021-03-11 16:47:30 +08:00
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
<#else>
<!-- 添加条件 -->
</#if>
</update>
</#if>
<!-- 删除${tableExplain}(物理) -->
<update id="delete" parameterType="map">
DELETE FROM
${tableFullName}
WHERE
<#if hasId>
${idColumn} IN
2021-03-11 16:47:30 +08:00
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
<#else>
<!-- 添加条件 -->
</#if>
</update>
<!-- 修改${tableExplain} -->
<update id="update" parameterType="map">
UPDATE
${tableFullName}
SET
<#list fieldList! as field>
<#if field.formShow>
<#if field.formFieldValue == "number" || field.formFieldValue == "double">
<if test="${field.propertyName} != null">
2021-03-21 00:22:08 +08:00
${field.columnName} = ${r"#{"}${field.propertyName}${r"}"},
</if>
<#elseif field.formFieldValue == "radio" || field.formFieldValue == "checkbox" || field.formFieldValue == "select">
<if test="${field.propertyName} != null">
2021-11-05 00:42:19 +08:00
${field.columnName} = ${r"#{"}${field.propertyName}${r"}"},
</if>
<#else>
2021-04-07 11:04:09 +08:00
<#if hasId>
<#if field.columnName != idColumn>
<if test="${field.propertyName} != null and ${field.propertyName} != ''">
${field.columnName} = ${r"#{"}${field.propertyName}${r"}"},
</if>
</#if>
<#else>
<if test="${field.propertyName} != null and ${field.propertyName} != ''">
2021-03-21 00:22:08 +08:00
${field.columnName} = ${r"#{"}${field.propertyName}${r"}"},
</if>
</#if>
</#if>
2021-03-11 16:47:30 +08:00
</#if>
</#list>
<#if hasGmtModified && !gmtModifiedFormShow>
2021-03-21 00:22:08 +08:00
gmt_modified = ${r"#{gmtModified}"},
</#if>
<#if hasModifier && !modifierFormShow>
2021-03-21 00:22:08 +08:00
modifier = ${r"#{modifier}"},
</#if>
<#if hasId>
${idColumn} = ${idColumn}
<#else>
2021-03-21 00:22:08 +08:00
<!-- 填充条件 -->
</#if>
2021-03-11 16:47:30 +08:00
WHERE
<#if hasId>
${idColumn} = ${r"#{"}${firstLowerTableName}${r"Id}"}
2021-03-11 16:47:30 +08:00
<#else>
<!-- 添加条件 -->
</#if>
</update>
<!-- ${tableExplain}详情 -->
<select id="get" parameterType="map" resultMap="${firstLowerTableName}DTO">
SELECT
<#list fieldList! as field>
<#if field.formShow>
t1.${field.columnName},
</#if>
</#list>
<#if hasId>
t1.${idColumn}
2021-03-11 16:47:30 +08:00
<#else>
1
</#if>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<#if hasId>
<if test="${firstLowerTableName}Id != null and ${firstLowerTableName}Id != ''">
AND
t1.${idColumn} = ${r"#{"}${firstLowerTableName}${r"Id}"}
2021-03-11 16:47:30 +08:00
</if>
<#else>
<!-- 添加条件 -->
</#if>
</select>
<!-- ${tableExplain}详情 -->
<select id="getBO" parameterType="map" resultMap="${firstLowerTableName}BO">
SELECT
<#list fieldList! as field>
t1.${field.columnName}${field.fieldSplit}
</#list>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<#if hasId>
<if test="${firstLowerTableName}Id != null and ${firstLowerTableName}Id != ''">
AND
t1.${idColumn} = ${r"#{"}${firstLowerTableName}${r"Id}"}
2021-03-11 16:47:30 +08:00
</if>
<#else>
<!-- 添加条件 -->
</#if>
</select>
<!-- ${tableExplain}详情 -->
<select id="getPO" parameterType="map" resultMap="${firstLowerTableName}PO">
SELECT
<#list fieldList! as field>
t1.${field.columnName}${field.fieldSplit}
</#list>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<#if hasId>
<if test="${firstLowerTableName}Id != null and ${firstLowerTableName}Id != ''">
AND
t1.${idColumn} = ${r"#{"}${firstLowerTableName}${r"Id}"}
2021-03-11 16:47:30 +08:00
</if>
<#else>
<!-- 添加条件 -->
</#if>
</select>
<!-- ${tableExplain}列表 -->
<select id="list" parameterType="map" resultMap="${firstLowerTableName}DTO">
SELECT
<#list fieldList! as field>
<#if field.listShow>
t1.${field.columnName},
</#if>
</#list>
2021-03-15 22:20:52 +08:00
1
2021-03-11 16:47:30 +08:00
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<if test="keywords != null and keywords != ''">
AND (
<!-- 这里添加其他条件 -->
t1.id LIKE CONCAT('%', ${r"#{keywords}"}, '%')
)
</if>
<#if hasGmtCreate>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> ${r"#{startTime}"}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> ${r"#{endTime}"}
</if>
</#if>
<#if hasId>
<if test="${firstLowerTableName}Ids != null and ${firstLowerTableName}Ids.size > 0">
AND
t1.${idColumn} IN
2021-03-11 16:47:30 +08:00
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
</if>
</#if>
</select>
<!-- ${tableExplain}列表 -->
<select id="listBO" parameterType="map" resultMap="${firstLowerTableName}BO">
SELECT
<#list fieldList! as field>
t1.${field.columnName}${field.fieldSplit}
</#list>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<if test="keywords != null and keywords != ''">
AND (
<!-- 这里添加其他条件 -->
t1.id LIKE CONCAT('%', ${r"#{keywords}"}, '%')
)
</if>
<#if hasGmtCreate>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> ${r"#{startTime}"}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> ${r"#{endTime}"}
</if>
</#if>
<#if hasId>
<if test="${firstLowerTableName}Ids != null and ${firstLowerTableName}Ids.size > 0">
AND
t1.${idColumn} IN
2021-03-11 16:47:30 +08:00
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
</if>
</#if>
</select>
<!-- ${tableExplain}列表 -->
<select id="listPO" parameterType="map" resultMap="${firstLowerTableName}PO">
SELECT
<#list fieldList! as field>
t1.${field.columnName}${field.fieldSplit}
</#list>
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
<if test="keywords != null and keywords != ''">
AND (
<!-- 这里添加其他条件 -->
t1.id LIKE CONCAT('%', ${r"#{keywords}"}, '%')
)
</if>
<#if hasGmtCreate>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> ${r"#{startTime}"}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> ${r"#{endTime}"}
</if>
</#if>
<#if hasId>
<if test="${firstLowerTableName}Ids != null and ${firstLowerTableName}Ids.size > 0">
AND
t1.${idColumn} IN
2021-03-11 16:47:30 +08:00
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
</if>
</#if>
</select>
<!-- ${tableExplain}统计 -->
<select id="count" parameterType="map" resultType="Integer">
SELECT
COUNT(*)
FROM
${tableFullName} t1
WHERE
<#if hasIsDelete>
t1.is_delete = 0
<#else>
1 = 1
</#if>
</select>
</mapper>