You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.5 KiB
116 lines
3.5 KiB
1 year ago
|
<?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="com.itheima.jvmoptimize.practice.demo.dao.TbArticleDao">
|
||
|
|
||
|
<resultMap type="com.itheima.jvmoptimize.practice.demo.pojo.TbArticle" id="ArticleMap">
|
||
|
<result property="id" column="id" jdbcType="INTEGER"/>
|
||
|
<result property="title" column="title" jdbcType="VARCHAR"/>
|
||
|
<result property="content" column="content" jdbcType="VARCHAR"/>
|
||
|
</resultMap>
|
||
|
|
||
|
<!--查询单个-->
|
||
|
<select id="queryById" resultMap="ArticleMap">
|
||
|
select id,
|
||
|
title,
|
||
|
content
|
||
|
from article
|
||
|
where id = #{id}
|
||
|
</select>
|
||
|
|
||
|
<!--查询指定行数据-->
|
||
|
<select id="queryAllByLimit" resultMap="ArticleMap">
|
||
|
select
|
||
|
id, title, content
|
||
|
from article
|
||
|
<where>
|
||
|
<if test="article.id != null">
|
||
|
and id = #{article.id}
|
||
|
</if>
|
||
|
<if test="article.title != null and article.title != ''">
|
||
|
and title = #{article.title}
|
||
|
</if>
|
||
|
<if test="article.content != null and article.content != ''">
|
||
|
and content = #{article.content}
|
||
|
</if>
|
||
|
</where>
|
||
|
limit #{pageable.offset}, #{pageable.pageSize}
|
||
|
</select>
|
||
|
|
||
|
<!--统计总行数-->
|
||
|
<select id="count" resultType="java.lang.Long">
|
||
|
select count(1)
|
||
|
from article
|
||
|
<where>
|
||
|
<if test="id != null">
|
||
|
and id = #{id}
|
||
|
</if>
|
||
|
<if test="title != null and title != ''">
|
||
|
and title = #{title}
|
||
|
</if>
|
||
|
<if test="content != null and content != ''">
|
||
|
and content = #{content}
|
||
|
</if>
|
||
|
</where>
|
||
|
</select>
|
||
|
|
||
|
<select id="countIfAbsent" resultType="java.lang.Long">
|
||
|
select
|
||
|
IFNULL(sum(1),0)
|
||
|
from article where
|
||
|
<if test="ids != null and ids.size() > 0">
|
||
|
id in
|
||
|
<foreach collection="ids" item="item" open="(" close=")" separator=",">
|
||
|
#{item}
|
||
|
</foreach>
|
||
|
</if>
|
||
|
</select>
|
||
|
|
||
|
<!--新增所有列-->
|
||
|
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
|
||
|
insert into article(title, content)
|
||
|
values (#{title}, #{content})
|
||
|
</insert>
|
||
|
|
||
|
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
|
||
|
insert into article(title, content)
|
||
|
values
|
||
|
<foreach collection="entities" item="entity" separator=",">
|
||
|
(#{entity.title}, #{entity.content})
|
||
|
</foreach>
|
||
|
</insert>
|
||
|
|
||
|
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
|
||
|
insert into article(title, content)
|
||
|
values
|
||
|
<foreach collection="entities" item="entity" separator=",">
|
||
|
(#{entity.title}, #{entity.content})
|
||
|
</foreach>
|
||
|
on duplicate key update
|
||
|
title = values(title),
|
||
|
content = values(content)
|
||
|
</insert>
|
||
|
|
||
|
<!--通过主键修改数据-->
|
||
|
<update id="update">
|
||
|
update article
|
||
|
<set>
|
||
|
<if test="title != null and title != ''">
|
||
|
title = #{title},
|
||
|
</if>
|
||
|
<if test="content != null and content != ''">
|
||
|
content = #{content},
|
||
|
</if>
|
||
|
</set>
|
||
|
where id = #{id}
|
||
|
</update>
|
||
|
|
||
|
<!--通过主键删除-->
|
||
|
<delete id="deleteById">
|
||
|
delete
|
||
|
from article
|
||
|
where id = #{id}
|
||
|
</delete>
|
||
|
|
||
|
</mapper>
|
||
|
|