Files
blog-backEnd/src/main/resources/mapper/articleMapper.xml
2019-11-28 19:18:16 +08:00

163 lines
5.5 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="cn.celess.blog.mapper.ArticleMapper">
<resultMap id="articleResultMap" type="cn.celess.blog.entity.Article">
<id column="a_id" property="id"/>
<result column="a_title" property="title"/>
<result column="a_summary" property="summary"/>
<result column="a_md_content" property="mdContent"/>
<result column="a_tags_id" property="tagsId"/>
<result column="a_category_id" property="categoryId"/>
<result column="a_url" property="url"/>
<result column="a_author_id" property="authorId"/>
<result column="a_is_open" property="open"/>
<result column="a_is_original" property="type"/>
<result column="next_a_id" property="nextArticleId"/>
<result column="pre_a_id" property="preArticleId"/>
<result column="a_reading_number" property="readingNumber"/>
<result column="a_publish_date" property="publishDate"/>
<result column="a_update_date" property="updateDate"/>
</resultMap>
<insert id="insert" parameterType="cn.celess.blog.entity.Article">
insert into article (a_author_id, a_category_id, a_tags_id, a_md_content, a_publish_date,
a_summary, a_title, a_url)
values (#{authorId}, #{categoryId}, #{tagsId}, #{mdContent}, #{publishDate},
#{summary}, #{title}, #{url})
<selectKey resultType="java.lang.Long" keyProperty="id">
SELECT LAST_INSERT_ID() AS id
</selectKey>
</insert>
<delete id="delete">
delete
from article
where a_id = #{id}
</delete>
<update id="update">
update article
set
<if test="title!=null">a_title=#{title},</if>
<if test="mdContent!=null">a_md_content=#{mdContent},</if>
<if test="summary!=null">a_summary=#{summary},</if>
<if test="type!=null">a_is_original=#{type},</if>
<if test="url!=null">a_url=#{url},</if>
<if test="updateDate!=null">a_update_date=#{updateDate},</if>
<if test="categoryId!=null">a_category_id=#{categoryId},</if>
<if test="tagsId!=null">a_tags_id=#{tagsId},</if>
<if test="nextArticleId!=null">next_a_id=#{nextArticleId},</if>
<if test="preArticleId!=null">pre_a_id=#{preArticleId},</if>
<if test="open!=null">a_is_open=#{open}</if>
where a_id = #{id}
</update>
<update id="updateNextArticleId">
update article
set next_a_id=#{nextArticleID}
where a_id = #{targetArticleID}
</update>
<update id="updatePreArticleId">
update article
set pre_a_id=#{preArticleID}
where a_id = #{targetArticleID}
</update>
<update id="setReadingNumber">
update article
set a_reading_number=#{number}
where a_id = #{id}
</update>
<select id="getLastestArticleId" resultType="long">
select a_id
from article
order by a_id desc
limit 1
</select>
<select id="getLastestArticle" resultMap="articleResultMap" resultType="cn.celess.blog.entity.Article">
select *
from article
order by a_id desc
limit 1
</select>
<select id="findArticleById" resultMap="articleResultMap">
select *
from article
where a_id = #{id}
</select>
<select id="existsByTitle" resultType="boolean">
SELECT EXISTS(SELECT * FROM article WHERE a_title = #{title})
</select>
<select id="existsById" resultType="boolean">
SELECT EXISTS(SELECT * FROM article WHERE a_id = #{id})
</select>
<select id="findAllByAuthorId" resultMap="articleResultMap">
select *
from article
where a_author_id = #{authorID}
order by a_id desc
</select>
<select id="findAllByOpen" resultMap="articleResultMap">
select *
from article
where a_is_open = #{isOpen}
order by a_id desc
</select>
<select id="getTitleById" resultType="string">
SELECT a_title
from article
where a_id = #{id}
</select>
<select id="findAllByCategoryId" resultMap="articleResultMap">
select a_id, a_title, a_summary
from article
where a_category_id = #{id}
order by a_id desc
</select>
<select id="findAll" resultMap="articleResultMap">
select *
from article
order by a_id desc
</select>
<select id="getSimpleInfo" resultMap="articleResultMap">
select a_id, a_summary, a_title
from article
where a_id = #{id}
</select>
<select id="getSimpleInfoByCategory" resultMap="articleResultMap">
select a_id, a_summary, a_title
from article
where a_category_id = #{categoryId}
order by a_id desc
</select>
<select id="getSimpleInfoByTag" resultMap="articleResultMap">
Select
a_id, a_summary, a_title
from article where a_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
order by a_id desc
</select>
<select id="count" resultType="long">
select count(*)
from article;
</select>
</mapper>