修改sql
This commit is contained in:
@@ -1,84 +1,91 @@
|
||||
<?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.CategoryMapper">
|
||||
<resultMap id="categoryResultMap" type="cn.celess.blog.entity.Category">
|
||||
<resultMap id="categoryResultMap" type="cn.celess.blog.entity.TagCategory">
|
||||
<id column="t_id" property="id"/>
|
||||
<result column="t_name" property="name"/>
|
||||
<result column="is_category" property="category"/>
|
||||
<result column="is_delete" property="deleted"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert">
|
||||
insert into category (c_name, articles)
|
||||
values (#{name}, #{articles});
|
||||
<selectKey resultType="java.lang.Long" keyProperty="id">
|
||||
SELECT LAST_INSERT_ID() AS id
|
||||
</selectKey>
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into tag_category (t_name, is_category)
|
||||
values (#{name}, true);
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update category
|
||||
set c_name=#{name},
|
||||
articles=#{articles}
|
||||
where c_id = #{id}
|
||||
update tag_category
|
||||
set t_name=#{name}
|
||||
where t_id = #{id}
|
||||
and is_category = true;
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
delete
|
||||
from category
|
||||
where c_id = #{id}
|
||||
</delete>
|
||||
<update id="delete">
|
||||
update tag_category
|
||||
set is_delete= true
|
||||
where t_id = #{id}
|
||||
and is_category = true;
|
||||
</update>
|
||||
|
||||
<select id="findCategoryByName" resultMap="categoryResultMap">
|
||||
select *
|
||||
from category
|
||||
where c_name = #{name}
|
||||
from tag_category
|
||||
where t_name = #{name}
|
||||
and is_category = true;
|
||||
</select>
|
||||
|
||||
<select id="findCategoryById" resultMap="categoryResultMap">
|
||||
select *
|
||||
from category
|
||||
where c_id = #{id}
|
||||
from tag_category
|
||||
where t_id = #{id}
|
||||
and is_category = true;
|
||||
</select>
|
||||
|
||||
<select id="findAll" resultMap="categoryResultMap">
|
||||
select *
|
||||
from category
|
||||
from tag_category
|
||||
where is_category = true;
|
||||
</select>
|
||||
|
||||
<select id="getAllName" resultType="java.lang.String">
|
||||
select c_name
|
||||
from category
|
||||
select t_name
|
||||
from tag_category
|
||||
where is_category = true;
|
||||
</select>
|
||||
|
||||
<select id="getNameById" resultType="java.lang.String">
|
||||
select c_name
|
||||
from category
|
||||
where c_id = #{id}
|
||||
select t_name
|
||||
from tag_category
|
||||
where is_category = true;
|
||||
</select>
|
||||
|
||||
<select id="getIDByName" resultType="java.lang.Long">
|
||||
select c_id
|
||||
from category
|
||||
where c_name = #{name}
|
||||
<select id="getIdByName" resultType="java.lang.Long">
|
||||
select t_id
|
||||
from tag_category
|
||||
where is_category = true
|
||||
and t_name = #{name}
|
||||
</select>
|
||||
|
||||
<select id="existsByName" resultType="java.lang.Boolean">
|
||||
SELECT EXISTS(SELECT * FROM category WHERE c_name = #{name})
|
||||
SELECT EXISTS(SELECT * FROM tag_category WHERE t_name = #{name} and is_category = true)
|
||||
</select>
|
||||
|
||||
<select id="existsById" resultType="java.lang.Boolean">
|
||||
SELECT EXISTS(SELECT * FROM category WHERE c_id = #{id})
|
||||
SELECT EXISTS(SELECT * FROM tag_category WHERE t_id = #{id})
|
||||
</select>
|
||||
|
||||
<select id="getLastestCategory" resultMap="categoryResultMap">
|
||||
select *
|
||||
from category
|
||||
order by c_id desc
|
||||
from tag_category
|
||||
where is_category = true
|
||||
order by t_id desc
|
||||
limit 1;
|
||||
</select>
|
||||
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from category;
|
||||
from tag_category
|
||||
where is_category = true;
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -7,7 +7,7 @@
|
||||
<result column="a_summary" property="summary"/>
|
||||
<result column="a_md_content" property="mdContent"/>
|
||||
<result column="a_url" property="url"/>
|
||||
<result column="a_author_id" property="authorId"/>
|
||||
<result column="a_author_id" property="user.id"/>
|
||||
<result column="a_is_open" property="open"/>
|
||||
<result column="a_is_original" property="type"/>
|
||||
<!-- <result column="next_a_id" property="nextArticleId"/>-->
|
||||
@@ -15,11 +15,12 @@
|
||||
<result column="a_reading_number" property="readingNumber"/>
|
||||
<result column="a_publish_date" property="publishDate"/>
|
||||
<result column="a_update_date" property="updateDate"/>
|
||||
<association property="category" column="a_category_id" javaType="cn.celess.blog.entity.Category"
|
||||
<result column="is_delete" property="deleted"/>
|
||||
<association property="category" column="a_category_id" javaType="cn.celess.blog.entity.TagCategory"
|
||||
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||
</association>
|
||||
<collection property="tags" ofType="cn.celess.blog.entity.Article"
|
||||
resultMap="cn.celess.blog.mapper.TagMapper.tagResultMap">
|
||||
<collection property="tags" ofType="cn.celess.blog.entity.TagCategory"
|
||||
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
@@ -37,6 +38,7 @@
|
||||
<result column="readingCount" property="readingNumber"/>
|
||||
<result column="publishDate" property="publishDate"/>
|
||||
<result column="updateDate" property="updateDate"/>
|
||||
<result column="isDelete" property="deleted"/>
|
||||
<association property="category" column="categoryId" javaType="cn.celess.blog.entity.Category">
|
||||
<id column="categoryId" property="id"/>
|
||||
<result column="categoryName" property="name"/>
|
||||
@@ -55,10 +57,9 @@
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="cn.celess.blog.entity.Article">
|
||||
insert into article (a_author_id, a_category_id, a_md_content, a_publish_date,
|
||||
insert into article (a_author_id, a_category_id, a_md_content, a_is_original,
|
||||
a_summary, a_title, a_url)
|
||||
values (#{user.id}, #{category.id}, #{mdContent}, #{publishDate},
|
||||
#{summary}, #{title}, #{url})
|
||||
values (#{user.id}, #{category.id}, #{mdContent}, #{type}, #{summary}, #{title}, #{url})
|
||||
</insert>
|
||||
<update id="delete">
|
||||
update article
|
||||
@@ -85,24 +86,18 @@
|
||||
where a_id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="getLastestArticle" resultMap="articleResultMap" resultType="cn.celess.blog.entity.Article">
|
||||
<select id="getLastestArticle" resultMap="articleViewResultMap" resultType="cn.celess.blog.entity.Article">
|
||||
select *
|
||||
from article,
|
||||
tag_category
|
||||
where tag_category.is_category = true
|
||||
and article.a_category_id = tag_category.t_id
|
||||
order by a_id desc
|
||||
from articleView
|
||||
order by articleId desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<select id="findArticleById" resultMap="articleResultMap">
|
||||
<select id="findArticleById" resultMap="articleViewResultMap">
|
||||
select *
|
||||
from article,
|
||||
tag_category
|
||||
where a_id = #{id}
|
||||
and tag_category.is_category = true
|
||||
and article.a_category_id = tag_category.t_id
|
||||
from articleView
|
||||
where articleId = #{id}
|
||||
</select>
|
||||
|
||||
<select id="existsByTitle" resultType="boolean">
|
||||
@@ -113,37 +108,40 @@
|
||||
select is_delete
|
||||
from article
|
||||
WHERE a_id = #{id}
|
||||
# SELECT EXISTS(SELECT * FROM article
|
||||
</select>
|
||||
|
||||
<select id="findAllByAuthorId" resultMap="articleResultMap">
|
||||
<select id="findAllByAuthorId" resultMap="articleViewResultMap">
|
||||
select *
|
||||
from article
|
||||
where a_author_id = #{authorID}
|
||||
order by a_id desc
|
||||
from articleView
|
||||
where authorId = #{authorID}
|
||||
and isDelete = false
|
||||
order by articleId desc
|
||||
</select>
|
||||
|
||||
<select id="findAllByOpen" resultMap="articleResultMap">
|
||||
<select id="findAllByOpen" resultMap="articleViewResultMap">
|
||||
select *
|
||||
from article
|
||||
where a_is_open = #{isOpen}
|
||||
order by a_id desc
|
||||
from articleView
|
||||
where isOpen = #{isOpen}
|
||||
and isDelete = false
|
||||
order by articleId desc
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getTitleById" resultType="string">
|
||||
SELECT a_title
|
||||
from article
|
||||
where a_id = #{id}
|
||||
SELECT title
|
||||
from articleView
|
||||
where articleId = #{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 id="findAllByCategoryId" resultMap="articleViewResultMap">
|
||||
select *
|
||||
from articleView
|
||||
where categoryId = #{id}
|
||||
and isDelete = false
|
||||
order by articleId desc
|
||||
</select>
|
||||
|
||||
|
||||
<select id="findAll" resultMap="articleViewResultMap">
|
||||
select *
|
||||
from articleView
|
||||
@@ -151,33 +149,11 @@
|
||||
order by articleId 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>
|
||||
@@ -1,75 +1,66 @@
|
||||
<?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.TagMapper">
|
||||
<resultMap id="tagResultMap" type="cn.celess.blog.entity.Tag">
|
||||
<id column="tag_id" property="id"/>
|
||||
<result column="tag_name" property="name"/>
|
||||
|
||||
<resultMap id="tagResultMap" type="cn.celess.blog.entity.Tag"
|
||||
extends="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert">
|
||||
insert into tag (tag_name, articles)
|
||||
VALUES (#{name}, #{articles});
|
||||
<selectKey resultType="java.lang.Long" keyProperty="id">
|
||||
SELECT LAST_INSERT_ID() AS id
|
||||
</selectKey>
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into tag_category (t_name, is_category)
|
||||
VALUES (#{name}, false);
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update tag
|
||||
set tag_name=#{name},
|
||||
articles=#{articles}
|
||||
where tag_id = #{id}
|
||||
update tag_category
|
||||
set t_name=#{name}
|
||||
where t_id = #{id}
|
||||
and is_category = false;
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
delete
|
||||
from tag
|
||||
where tag_id = #{id}
|
||||
</delete>
|
||||
<update id="delete">
|
||||
update tag_category
|
||||
set is_delete = true
|
||||
where t_id = #{id}
|
||||
and is_category = false;
|
||||
</update>
|
||||
|
||||
<select id="findTagById" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag
|
||||
where tag_id = #{id}
|
||||
from tag_category
|
||||
where t_id = #{id}
|
||||
and is_category = false;
|
||||
</select>
|
||||
|
||||
<select id="findTagByName" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag
|
||||
where tag_name = #{name}
|
||||
from tag_category
|
||||
where t_name = #{name}
|
||||
and is_category = false;
|
||||
</select>
|
||||
|
||||
<select id="existsByName" resultType="boolean">
|
||||
SELECT EXISTS(SELECT * FROM tag WHERE tag_name = #{name})
|
||||
SELECT EXISTS(SELECT * FROM tag_category WHERE t_name = #{name} and is_category = false)
|
||||
</select>
|
||||
|
||||
<select id="getIDByName" resultType="long">
|
||||
select tag_id
|
||||
from tag
|
||||
where tag_name = #{name}
|
||||
</select>
|
||||
|
||||
<select id="getNameById" resultType="string">
|
||||
select tag_name
|
||||
from tag
|
||||
where tag_id = #{id}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getLastestTag" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag
|
||||
order by tag_id desc
|
||||
from tag_category
|
||||
where is_category = false
|
||||
order by t_id desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="findAll" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag
|
||||
from tag_category
|
||||
where is_category = false;
|
||||
</select>
|
||||
|
||||
<select id="count" resultType="long">
|
||||
select count(*)
|
||||
from tag;
|
||||
from tag_category
|
||||
where is_category = false;;
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user