博客系统mapper.xml的分析(4)
鉴于剩下的都大差不差,把xml文件都打了下备注就复制上了!!!(究极偷懒王)
BlogCommentMapper.xml
博客评论映射器
<!-- 基列列表-->
<sql id="Base_Column_List">
comment_id, blog_id, commentator, email, website_url, comment_body, comment_create_time,
commentator_ip, reply_body, reply_create_time, comment_status, is_deleted
</sql>
<!-- 查找博客评论列表-->
<select id="findBlogCommentList" parameterType="Map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tb_blog_comment
where is_deleted=0
<if test="blogId!=null">
AND blog_id = #{blogId}
</if>
<if test="commentStatus!=null">
AND comment_status = #{commentStatus}
</if>
order by comment_id desc
<if test="start!=null and limit!=null">
limit #{start},#{limit}
</if>
</select>
<!--获取总博客评论数-->
<select id="getTotalBlogComments" parameterType="Map" resultType="int">
select count(*) from tb_blog_comment
where is_deleted=0
<if test="blogId!=null">
AND blog_id = #{blogId}
</if>
<if test="commentStatus!=null">
AND comment_status = #{commentStatus}
</if>
</select>
<!-- 按主键查询 -->
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tb_blog_comment
where comment_id = #{commentId,jdbcType=BIGINT} and is_deleted=0
</select>
<!-- 按主键删除-->
<update id="deleteByPrimaryKey" parameterType="java.lang.Long">
update tb_blog_comment set is_deleted=1
where comment_id = #{commentId,jdbcType=BIGINT} and is_deleted=0
</update>
<!-- 检查完成 不知道做什么用的-->
<update id="checkDone">
update tb_blog_comment
set comment_status=1 where comment_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
and comment_status = 0
</update>
<!-- 删除批次批量删除评论-->
<update id="deleteBatch">
update tb_blog_comment
set is_deleted=1 where comment_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<!-- 插入 -->
<insert id="insert" parameterType="com.site.blog.my.core.entity.BlogComment">
insert into tb_blog_comment (comment_id, blog_id, commentator,
email, website_url, comment_body,
comment_create_time, commentator_ip, reply_body,
reply_create_time, comment_status, is_deleted
)
values (#{commentId,jdbcType=BIGINT}, #{blogId,jdbcType=BIGINT}, #{commentator,jdbcType=VARCHAR},
#{email,jdbcType=VARCHAR}, #{websiteUrl,jdbcType=VARCHAR}, #{commentBody,jdbcType=VARCHAR},
#{commentCreateTime,jdbcType=TIMESTAMP}, #{commentatorIp,jdbcType=VARCHAR}, #{replyBody,jdbcType=VARCHAR},
#{replyCreateTime,jdbcType=TIMESTAMP}, #{commentStatus,jdbcType=TINYINT}, #{isDeleted,jdbcType=TINYINT}
)
</insert>
<!-- 选择性 插入-->
<insert id="insertSelective" parameterType="com.site.blog.my.core.entity.BlogComment">
insert into tb_blog_comment
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="commentId != null">
comment_id,
</if>
<if test="blogId != null">
blog_id,
</if>
<if test="commentator != null">
commentator,
</if>
<if test="email != null">
email,
</if>
<if test="websiteUrl != null">
website_url,
</if>
<if test="commentBody != null">
comment_body,
</if>
<if test="commentCreateTime != null">
comment_create_time,
</if>
<if test="commentatorIp != null">
commentator_ip,
</if>
<if test="replyBody != null">
reply_body,
</if>
<if test="replyCreateTime != null">
reply_create_time,
</if>
<if test="commentStatus != null">
comment_status,
</if>
<if test="isDeleted != null">
is_deleted,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="commentId != null">
#{commentId,jdbcType=BIGINT},
</if>
<if test="blogId != null">
#{blogId,jdbcType=BIGINT},
</if>
<if test="commentator != null">
#{commentator,jdbcType=VARCHAR},
</if>
<if test="email != null">
#{email,jdbcType=VARCHAR},
</if>
<if test="websiteUrl != null">
#{websiteUrl,jdbcType=VARCHAR},
</if>
<if test="commentBody != null">
#{commentBody,jdbcType=VARCHAR},
</if>
<if test="commentCreateTime != null">
#{commentCreateTime,jdbcType=TIMESTAMP},
</if>
<if test="commentatorIp != null">
#{commentatorIp,jdbcType=VARCHAR},
</if>
<if test="replyBody != null">
#{replyBody,jdbcType=VARCHAR},
</if>
<if test="replyCreateTime != null">
#{replyCreateTime,jdbcType=TIMESTAMP},
</if>
<if test="commentStatus != null">
#{commentStatus,jdbcType=TINYINT},
</if>
<if test="isDeleted != null">
#{isDeleted,jdbcType=TINYINT},
</if>
</trim>
</insert>
<!-- 按主键选择性更新 -->
<update id="updateByPrimaryKeySelective" parameterType="com.site.blog.my.core.entity.BlogComment">
update tb_blog_comment
<set>
<if test="blogId != null">
blog_id = #{blogId,jdbcType=BIGINT},
</if>
<if test="commentator != null">
commentator = #{commentator,jdbcType=VARCHAR},
</if>
<if test="email != null">
email = #{email,jdbcType=VARCHAR},
</if>
<if test="websiteUrl != null">
website_url = #{websiteUrl,jdbcType=VARCHAR},
</if>
<if test="commentBody != null">
comment_body = #{commentBody,jdbcType=VARCHAR},
</if>
<if test="commentCreateTime != null">
comment_create_time = #{commentCreateTime,jdbcType=TIMESTAMP},
</if>
<if test="commentatorIp != null">
commentator_ip = #{commentatorIp,jdbcType=VARCHAR},
</if>
<if test="replyBody != null">
reply_body = #{replyBody,jdbcType=VARCHAR},
</if>
<if test="replyCreateTime != null">
reply_create_time = #{replyCreateTime,jdbcType=TIMESTAMP},
</if>
<if test="commentStatus != null">
comment_status = #{commentStatus,jdbcType=TINYINT},
</if>
<if test="isDeleted != null">
is_deleted = #{isDeleted,jdbcType=TINYINT},
</if>
</set>
where comment_id = #{commentId,jdbcType=BIGINT}
</update>
<!-- 按主键更新-->
<update id="updateByPrimaryKey" parameterType="com.site.blog.my.core.entity.BlogComment">
update tb_blog_comment
set blog_id = #{blogId,jdbcType=BIGINT},
commentator = #{commentator,jdbcType=VARCHAR},
email = #{email,jdbcType=VARCHAR},
website_url = #{websiteUrl,jdbcType=VARCHAR},
comment_body = #{commentBody,jdbcType=VARCHAR},
comment_create_time = #{commentCreateTime,jdbcType=TIMESTAMP},
commentator_ip = #{commentatorIp,jdbcType=VARCHAR},
reply_body = #{replyBody,jdbcType=VARCHAR},
reply_create_time = #{replyCreateTime,jdbcType=TIMESTAMP},
comment_status = #{commentStatus,jdbcType=TINYINT},
is_deleted = #{isDeleted,jdbcType=TINYINT}
where comment_id = #{commentId,jdbcType=BIGINT}
</update>
- 对应的方法
public interface BlogCommentMapper {
int deleteByPrimaryKey(Long commentId);
int insert(BlogComment record);
int insertSelective(BlogComment record);
BlogComment selectByPrimaryKey(Long commentId);
int updateByPrimaryKeySelective(BlogComment record);
int updateByPrimaryKey(BlogComment record);
List<BlogComment> findBlogCommentList(Map map);
int getTotalBlogComments(Map map);
int checkDone(Integer[] ids);
int deleteBatch(Integer[] ids);
}
BlogConfigMapper.xml
博客配置映射器
<!-- 基列列表 -->
<sql id="Base_Column_List">
config_name, config_value, create_time, update_time
</sql>
<!-- 按照主键查询-->
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tb_config
where config_name = #{configName,jdbcType=VARCHAR}
</select>
<!-- 全选-->
<select id="selectAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tb_config
</select>
<!-- 按主键选择性更新-->
<update id="updateByPrimaryKeySelective" parameterType="com.site.blog.my.core.entity.BlogConfig">
update tb_config
<set>
<if test="configValue != null">
config_value = #{configValue,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where config_name = #{configName,jdbcType=VARCHAR}
</update>
- 对应的方法
public interface BlogConfigMapper {
List<BlogConfig> selectAll();
BlogConfig selectByPrimaryKey(String configName);
int updateByPrimaryKeySelective(BlogConfig record);
}
BlogLinkMapper.xml
博客友链映射器
<!-- 基列列表-->
<sql id="Base_Column_List">
link_id, link_type, link_name, link_url, link_description, link_rank, is_deleted,
create_time
</sql>
<!-- 按主键选择-->
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tb_link
where link_id = #{linkId,jdbcType=INTEGER} AND is_deleted = 0
</select>
<!-- 按主键删除-->
<update id="deleteByPrimaryKey" parameterType="java.lang.Integer">
UPDATE tb_link SET is_deleted = 1
where link_id = #{linkId,jdbcType=INTEGER} AND is_deleted = 0
</update>
<!--删除批次-->
<update id="deleteBatch">
update tb_link
set is_deleted=1 where link_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<!--查找链接列表-->
<select id="findLinkList" parameterType="Map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tb_link
where is_deleted=0
order by link_id desc
<if test="start!=null and limit!=null">
limit #{start},#{limit}
</if>
</select>
<!--获取总链接数-->
<select id="getTotalLinks" parameterType="Map" resultType="int">
select count(*) from tb_link
where is_deleted=0
</select>
<!-- 插入-->
<insert id="insert" parameterType="com.site.blog.my.core.entity.BlogLink">
insert into tb_link (link_id, link_type, link_name,
link_url, link_description, link_rank,
is_deleted, create_time)
values (#{linkId,jdbcType=INTEGER}, #{linkType,jdbcType=TINYINT}, #{linkName,jdbcType=VARCHAR},
#{linkUrl,jdbcType=VARCHAR}, #{linkDescription,jdbcType=VARCHAR}, #{linkRank,jdbcType=INTEGER},
#{isDeleted,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP})
</insert>
<!-- 插入选择性-->
<insert id="insertSelective" parameterType="com.site.blog.my.core.entity.BlogLink">
insert into tb_link
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="linkId != null">
link_id,
</if>
<if test="linkType != null">
link_type,
</if>
<if test="linkName != null">
link_name,
</if>
<if test="linkUrl != null">
link_url,
</if>
<if test="linkDescription != null">
link_description,
</if>
<if test="linkRank != null">
link_rank,
</if>
<if test="isDeleted != null">
is_deleted,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="linkId != null">
#{linkId,jdbcType=INTEGER},
</if>
<if test="linkType != null">
#{linkType,jdbcType=TINYINT},
</if>
<if test="linkName != null">
#{linkName,jdbcType=VARCHAR},
</if>
<if test="linkUrl != null">
#{linkUrl,jdbcType=VARCHAR},
</if>
<if test="linkDescription != null">
#{linkDescription,jdbcType=VARCHAR},
</if>
<if test="linkRank != null">
#{linkRank,jdbcType=INTEGER},
</if>
<if test="isDeleted != null">
#{isDeleted,jdbcType=TINYINT},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<!-- 按主键选择性更新-->
<update id="updateByPrimaryKeySelective" parameterType="com.site.blog.my.core.entity.BlogLink">
update tb_link
<set>
<if test="linkType != null">
link_type = #{linkType,jdbcType=TINYINT},
</if>
<if test="linkName != null">
link_name = #{linkName,jdbcType=VARCHAR},
</if>
<if test="linkUrl != null">
link_url = #{linkUrl,jdbcType=VARCHAR},
</if>
<if test="linkDescription != null">
link_description = #{linkDescription,jdbcType=VARCHAR},
</if>
<if test="linkRank != null">
link_rank = #{linkRank,jdbcType=INTEGER},
</if>
<if test="isDeleted != null">
is_deleted = #{isDeleted,jdbcType=TINYINT},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</set>
where link_id = #{linkId,jdbcType=INTEGER}
</update>
<!-- 按主键更新-->
<update id="updateByPrimaryKey" parameterType="com.site.blog.my.core.entity.BlogLink">
update tb_link
set link_type = #{linkType,jdbcType=TINYINT},
link_name = #{linkName,jdbcType=VARCHAR},
link_url = #{linkUrl,jdbcType=VARCHAR},
link_description = #{linkDescription,jdbcType=VARCHAR},
link_rank = #{linkRank,jdbcType=INTEGER},
is_deleted = #{isDeleted,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=TIMESTAMP}
where link_id = #{linkId,jdbcType=INTEGER}
</update>
- 对应的方法
public interface BlogLinkMapper {
int deleteByPrimaryKey(Integer linkId);
int insert(BlogLink record);
int insertSelective(BlogLink record);
BlogLink selectByPrimaryKey(Integer linkId);
int updateByPrimaryKeySelective(BlogLink record);
int updateByPrimaryKey(BlogLink record);
List<BlogLink> findLinkList(PageQueryUtil pageUtil);
int getTotalLinks(PageQueryUtil pageUtil);
int deleteBatch(Integer[] ids);
}
- 友链实例
public class BlogLink {
private Integer linkId;
private Byte linkType;
private String linkName;
private String linkUrl;
private String linkDescription;
private Integer linkRank;
private Byte isDeleted;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
public Integer getLinkId() {
return linkId;
}
public void setLinkId(Integer linkId) {
this.linkId = linkId;
}
public Byte getLinkType() {
return linkType;
}
public void setLinkType(Byte linkType) {
this.linkType = linkType;
}
public String getLinkName() {
return linkName;
}
public void setLinkName(String linkName) {
this.linkName = linkName == null ? null : linkName.trim();
}
public String getLinkUrl() {
return linkUrl;
}
public void setLinkUrl(String linkUrl) {
this.linkUrl = linkUrl == null ? null : linkUrl.trim();
}
public String getLinkDescription() {
return linkDescription;
}
public void setLinkDescription(String linkDescription) {
this.linkDescription = linkDescription == null ? null : linkDescription.trim();
}
public Integer getLinkRank() {
return linkRank;
}
public void setLinkRank(Integer linkRank) {
this.linkRank = linkRank;
}
public Byte getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Byte isDeleted) {
this.isDeleted = isDeleted;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", linkId=").append(linkId);
sb.append(", linkType=").append(linkType);
sb.append(", linkName=").append(linkName);
sb.append(", linkUrl=").append(linkUrl);
sb.append(", linkDescription=").append(linkDescription);
sb.append(", linkRank=").append(linkRank);
sb.append(", isDeleted=").append(isDeleted);
sb.append(", createTime=").append(createTime);
sb.append("]");
return sb.toString();
}
}
BlogTagMapper.xml
博客标签映射器
<sql id="Base_Column_List">
tag_id, tag_name, is_deleted, create_time
</sql>
<!-- 查找标签列表-->
<select id="findTagList" parameterType="Map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tb_blog_tag
where is_deleted=0
order by tag_id desc
<if test="start!=null and limit!=null">
limit #{start},#{limit}
</if>
</select>
<!--获取标签计数-->
<select id="getTagCount" resultMap="BaseCountResultMap">
SELECT t_r.*,t.tag_name FROM
(SELECT r.tag_id,r.tag_count FROM
(SELECT tag_id ,COUNT(*) AS tag_count FROM
(SELECT tr.tag_id FROM tb_blog_tag_relation tr LEFT JOIN tb_blog b ON tr.blog_id = b.blog_id WHERE b.is_deleted=0)
trb GROUP BY tag_id) r ORDER BY tag_count DESC LIMIT 20 ) AS t_r LEFT JOIN tb_blog_tag t ON t_r.tag_id = t.tag_id WHERE t.is_deleted=0
</select>
<!-- 获取总标签数-->
<select id="getTotalTags" parameterType="Map" resultType="int">
select count(*) from tb_blog_tag
where is_deleted=0
</select>
<!-- 按主键选择-->
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tb_blog_tag
where tag_id = #{tagId,jdbcType=INTEGER} AND is_deleted = 0
</select>
<!-- 按标签名称选择-->
<select id="selectByTagName" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tb_blog_tag
where tag_name = #{tagName,jdbcType=VARCHAR} AND is_deleted = 0
</select>
<!-- 按主键删除-->
<update id="deleteByPrimaryKey" parameterType="java.lang.Integer">
update tb_blog_tag set is_deleted = 1
where tag_id = #{tagId,jdbcType=INTEGER}
</update>
<!-- 删除批次-->
<update id="deleteBatch">
update tb_blog_tag
set is_deleted=1 where tag_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<!-- 批量插入博客标签-->
<insert id="batchInsertBlogTag" parameterType="java.util.List" useGeneratedKeys="true"
keyProperty="tagId">
INSERT into tb_blog_tag(tag_name)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.tagName,jdbcType=VARCHAR})
</foreach>
</insert>
<!-- 插入 -->
<insert id="insert" parameterType="com.site.blog.my.core.entity.BlogTag">
insert into tb_blog_tag (tag_id, tag_name, is_deleted,
create_time)
values (#{tagId,jdbcType=INTEGER}, #{tagName,jdbcType=VARCHAR}, #{isDeleted,jdbcType=TINYINT},
#{createTime,jdbcType=TIMESTAMP})
</insert>
<!-- 插入选择性-->
<insert id="insertSelective" parameterType="com.site.blog.my.core.entity.BlogTag">
insert into tb_blog_tag
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="tagId != null">
tag_id,
</if>
<if test="tagName != null">
tag_name,
</if>
<if test="isDeleted != null">
is_deleted,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="tagId != null">
#{tagId,jdbcType=INTEGER},
</if>
<if test="tagName != null">
#{tagName,jdbcType=VARCHAR},
</if>
<if test="isDeleted != null">
#{isDeleted,jdbcType=TINYINT},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<!-- 按主键选择性更新-->
<update id="updateByPrimaryKeySelective" parameterType="com.site.blog.my.core.entity.BlogTag">
update tb_blog_tag
<set>
<if test="tagName != null">
tag_name = #{tagName,jdbcType=VARCHAR},
</if>
<if test="isDeleted != null">
is_deleted = #{isDeleted,jdbcType=TINYINT},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</set>
where tag_id = #{tagId,jdbcType=INTEGER}
</update>
<!-- 按主键更新-->
<update id="updateByPrimaryKey" parameterType="com.site.blog.my.core.entity.BlogTag">
update tb_blog_tag
set tag_name = #{tagName,jdbcType=VARCHAR},
is_deleted = #{isDeleted,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=TIMESTAMP}
where tag_id = #{tagId,jdbcType=INTEGER}
</update>
- 对应的方法
public interface BlogTagMapper {
int deleteByPrimaryKey(Integer tagId);
int insert(BlogTag record);
int insertSelective(BlogTag record);
BlogTag selectByPrimaryKey(Integer tagId);
BlogTag selectByTagName(String tagName);
int updateByPrimaryKeySelective(BlogTag record);
int updateByPrimaryKey(BlogTag record);
List<BlogTag> findTagList(PageQueryUtil pageUtil);
List<BlogTagCount> getTagCount();
int getTotalTags(PageQueryUtil pageUtil);
int deleteBatch(Integer[] ids);
int batchInsertBlogTag(List<BlogTag> tagList);
}
- 标签实体类
public class BlogTag {
private Integer tagId;
private String tagName;
private Byte isDeleted;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
public Integer getTagId() {
return tagId;
}
public void setTagId(Integer tagId) {
this.tagId = tagId;
}
public String getTagName() {
return tagName;
}
public void setTagName(String tagName) {
this.tagName = tagName == null ? null : tagName.trim();
}
public Byte getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Byte isDeleted) {
this.isDeleted = isDeleted;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", tagId=").append(tagId);
sb.append(", tagName=").append(tagName);
sb.append(", isDeleted=").append(isDeleted);
sb.append(", createTime=").append(createTime);
sb.append("]");
return sb.toString();
}
}
BlogTagRelationMapper.xml
博客标签关系映射器
<sql id="Base_Column_List">
relation_id, blog_id, tag_id, create_time
</sql>
<!-- 按主键选择-->
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tb_blog_tag_relation
where relation_id = #{relationId,jdbcType=BIGINT}
</select>
<!-- 按博客 ID 和标签 ID 选择-->
<select id="selectByBlogIdAndTagId" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tb_blog_tag_relation
where blog_id = #{blogId,jdbcType=BIGINT} and tag_id = #{tagId,jdbcType=INTEGER} limit 1
</select>
<!-- 选择不同的标签 ID-->
<select id="selectDistinctTagIds" resultType="java.lang.Long">
select
DISTINCT(tag_id)
from tb_blog_tag_relation
where tag_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<!-- 按主键删除-->
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from tb_blog_tag_relation
where relation_id = #{relationId,jdbcType=BIGINT}
</delete>
<!-- 按博客 ID 删除-->
<delete id="deleteByBlogId" parameterType="java.lang.Long">
delete from tb_blog_tag_relation
where blog_id = #{blogId,jdbcType=BIGINT}
</delete>
<!-- 插入-->
<insert id="insert" parameterType="com.site.blog.my.core.entity.BlogTagRelation">
insert into tb_blog_tag_relation (relation_id, blog_id, tag_id,
create_time)
values (#{relationId,jdbcType=BIGINT}, #{blogId,jdbcType=BIGINT}, #{tagId,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP})
</insert>
<!-- 插入选择性-->
<insert id="insertSelective" parameterType="com.site.blog.my.core.entity.BlogTagRelation">
insert into tb_blog_tag_relation
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="relationId != null">
relation_id,
</if>
<if test="blogId != null">
blog_id,
</if>
<if test="tagId != null">
tag_id,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="relationId != null">
#{relationId,jdbcType=BIGINT},
</if>
<if test="blogId != null">
#{blogId,jdbcType=BIGINT},
</if>
<if test="tagId != null">
#{tagId,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<!-- 批量插入-->
<insert id="batchInsert" parameterType="java.util.List">
INSERT into tb_blog_tag_relation(blog_id,tag_id)
VALUES
<foreach collection="relationList" item="item" separator=",">
(#{item.blogId,jdbcType=BIGINT},#{item.tagId,jdbcType=INTEGER})
</foreach>
</insert>
<!-- 按主键选择性更新-->
<update id="updateByPrimaryKeySelective" parameterType="com.site.blog.my.core.entity.BlogTagRelation">
update tb_blog_tag_relation
<set>
<if test="blogId != null">
blog_id = #{blogId,jdbcType=BIGINT},
</if>
<if test="tagId != null">
tag_id = #{tagId,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</set>
where relation_id = #{relationId,jdbcType=BIGINT}
</update>
<!-- 按主键更新-->
<update id="updateByPrimaryKey" parameterType="com.site.blog.my.core.entity.BlogTagRelation">
update tb_blog_tag_relation
set blog_id = #{blogId,jdbcType=BIGINT},
tag_id = #{tagId,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP}
where relation_id = #{relationId,jdbcType=BIGINT}
</update>
- 对应的方法
public interface BlogTagRelationMapper {
int deleteByPrimaryKey(Long relationId);
int insert(BlogTagRelation record);
int insertSelective(BlogTagRelation record);
BlogTagRelation selectByPrimaryKey(Long relationId);
BlogTagRelation selectByBlogIdAndTagId(@Param("blogId") Long blogId, @Param("tagId") Integer tagId);
List<Long> selectDistinctTagIds(Integer[] tagIds);
int updateByPrimaryKeySelective(BlogTagRelation record);
int updateByPrimaryKey(BlogTagRelation record);
int batchInsert(@Param("relationList") List<BlogTagRelation> blogTagRelationList);
int deleteByBlogId(Long blogId);
}
- 实体类
public class BlogTagRelation {
private Long relationId;
private Long blogId;
private Integer tagId;
private Date createTime;
public Long getRelationId() {
return relationId;
}
public void setRelationId(Long relationId) {
this.relationId = relationId;
}
public Long getBlogId() {
return blogId;
}
public void setBlogId(Long blogId) {
this.blogId = blogId;
}
public Integer getTagId() {
return tagId;
}
public void setTagId(Integer tagId) {
this.tagId = tagId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", relationId=").append(relationId);
sb.append(", blogId=").append(blogId);
sb.append(", tagId=").append(tagId);
sb.append(", createTime=").append(createTime);
sb.append("]");
return sb.toString();
}
}