Files
student-Management-system/sms-auth/sms-auth-infra/src/main/resources/mapper/ClazzDao.xml
2024-03-05 18:04:58 +08:00

100 lines
2.9 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="com.landaiqing.infra.basic.dao.ClazzDao">
<resultMap type="com.landaiqing.infra.basic.entity.Clazz" id="ClazzMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="className" column="class_name" jdbcType="VARCHAR"/>
<result property="num" column="num" jdbcType="INTEGER"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="ClazzMap">
select
id,class_name,num
from clazz
where id = #{id}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="ClazzMap">
select
id,class_name,num
from clazz
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="className != null and className != ''">
and class_name = #{className}
</if>
<if test="num != null">
and num = #{num}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from clazz
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="className != null and className != ''">
and class_name = #{className}
</if>
<if test="num != null">
and num = #{num}
</if>
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into clazz(class_name, num)
values (#{className}, #{num})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into clazz(class_name,num)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.className},#{entity.num})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into clazz(class_name,num)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.className},#{entity.num})
</foreach>
on duplicate key update
class_name = values(class_name)num = values(num)
</insert>
<!--通过主键修改数据-->
<update id="update">
update clazz
<set>
<if test="className != null and className != ''">
class_name = #{className},
</if>
<if test="num != null">
num = #{num},
</if>
</set>
where id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from clazz where id = #{id}
</delete>
</mapper>