236 lines
9.7 KiB
XML

<?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="xyz.zinglizingli.books.mapper.BookContentMapper">
<resultMap id="BaseResultMap" type="xyz.zinglizingli.books.po.BookContent">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="book_id" property="bookId" jdbcType="BIGINT"/>
<result column="index_id" property="indexId" jdbcType="BIGINT"/>
<result column="index_num" property="indexNum" jdbcType="INTEGER"/>
<result column="content" property="content" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" suffix=")" prefixOverrides="and">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")"
separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" suffix=")" prefixOverrides="and">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")"
separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, book_id, index_id, index_num, content
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="xyz.zinglizingli.books.po.BookContentExample">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List"/>
from book_content
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from book_content
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from book_content
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="xyz.zinglizingli.books.po.BookContentExample">
delete from book_content
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</delete>
<insert id="insert" parameterType="xyz.zinglizingli.books.po.BookContent">
insert into book_content (id, book_id, index_id,
index_num, content)
values (#{id,jdbcType=BIGINT}, #{bookId,jdbcType=BIGINT}, #{indexId,jdbcType=BIGINT},
#{indexNum,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="xyz.zinglizingli.books.po.BookContent">
insert into book_content
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="bookId != null">
book_id,
</if>
<if test="indexId != null">
index_id,
</if>
<if test="indexNum != null">
index_num,
</if>
<if test="content != null">
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="bookId != null">
#{bookId,jdbcType=BIGINT},
</if>
<if test="indexId != null">
#{indexId,jdbcType=BIGINT},
</if>
<if test="indexNum != null">
#{indexNum,jdbcType=INTEGER},
</if>
<if test="content != null">
#{content,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="xyz.zinglizingli.books.po.BookContentExample"
resultType="java.lang.Integer">
select count(*) from book_content
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update book_content
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.bookId != null">
book_id = #{record.bookId,jdbcType=BIGINT},
</if>
<if test="record.indexId != null">
index_id = #{record.indexId,jdbcType=BIGINT},
</if>
<if test="record.indexNum != null">
index_num = #{record.indexNum,jdbcType=INTEGER},
</if>
<if test="record.content != null">
content = #{record.content,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExample" parameterType="map">
update book_content
set id = #{record.id,jdbcType=BIGINT},
book_id = #{record.bookId,jdbcType=BIGINT},
index_id = #{record.indexId,jdbcType=BIGINT},
index_num = #{record.indexNum,jdbcType=INTEGER},
content = #{record.content,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="xyz.zinglizingli.books.po.BookContent">
update book_content
<set>
<if test="bookId != null">
book_id = #{bookId,jdbcType=BIGINT},
</if>
<if test="indexId != null">
index_id = #{indexId,jdbcType=BIGINT},
</if>
<if test="indexNum != null">
index_num = #{indexNum,jdbcType=INTEGER},
</if>
<if test="content != null">
content = #{content,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="xyz.zinglizingli.books.po.BookContent">
update book_content
set book_id = #{bookId,jdbcType=BIGINT},
index_id = #{indexId,jdbcType=BIGINT},
index_num = #{indexNum,jdbcType=INTEGER},
content = #{content,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<insert id="insertBatch" parameterType="java.util.List">
insert into book_content (book_id, index_num, content)
values
<foreach collection="list" item="item" index="index"
separator=",">
<trim prefix="(" suffix=")" suffixOverrides=",">
#{item.bookId,jdbcType=VARCHAR},
#{item.indexNum,jdbcType=VARCHAR},
#{item.content,jdbcType=VARCHAR},
</trim>
</foreach>
</insert>
<delete id="clearInvilidContent">
delete t1 from book_content t1 left join book_index t2
on t1.book_id = t2.book_id and t1.index_num = t2.index_num
left join book t3 on t1.book_id = t3.id
where t2.id is null or t3.id is null
</delete>
</mapper>