调整数据库字段,优化部分接口 #1

Merged
xiaohai2271 merged 33 commits from dev into master 2020-05-27 16:45:03 +08:00
2 changed files with 76 additions and 1 deletions
Showing only changes of commit 0136435a41 - Show all commits

View File

@@ -35,7 +35,6 @@ CREATE TABLE `tag_category`
`t_id` bigint(20) primary key auto_increment,
`t_name` varchar(255) not null,
`is_category` boolean not null default true,
`is_delete` boolean not null default false comment '该数据是否被删除'
) comment '标签和分类表';
CREATE TABLE `comment`

View File

@@ -0,0 +1,76 @@
<?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.ArticleTagMapper">
<resultMap id="articleTagResultMap" type="cn.celess.blog.entity.ArticleTag">
<id column="at_id" property="id"/>
<result column="a_id" property="article.id"/>
<result column="t_id" property="tag.id"/>
<association property="article" column="a_id" resultMap="cn.celess.blog.mapper.ArticleMapper.articleResultMap"
javaType="cn.celess.blog.entity.Article">
</association>
<association property="tag" column="t_id" resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap"
javaType="cn.celess.blog.entity.TagCategory">
</association>
</resultMap>
<!--新增-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into article_tag(a_id, t_id)
values (#{article.id}, #{tag.id})
</insert>
<!--通过主键修改数据-->
<update id="update">
update article_tag
<set>
<if test="article!=null and article.id != null">
a_id = #{article.id},
</if>
<if test="tag!=null and tag.id != null">
t_id = #{tag.id},
</if>
</set>
where at_id = #{tag.id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete
from article_tag
where at_id = #{id};
</delete>
<delete id="deleteMultiById">
delete from article_tag where at_id in
<foreach item="item" collection="list" separator=",">
(#{articleTag.id})
</foreach>
</delete>
<!--通过主键删除-->
<update id="deleteByArticleId">
delete
from article_tag
where a_id = #{id}
</update>
<select id="findAllByArticleId" resultMap="articleTagResultMap">
select *
from article_tag,
tag_category
where a_id = #{articleId}
and article_tag.t_id = tag_category.t_id
</select>
<select id="findOneById" resultMap="articleTagResultMap">
select *
from article_tag,
article,
tag_category
where article_tag.a_id = article.a_id
and tag_category.t_id = article_tag.t_id
</select>
</mapper>