SpringBoot中的增删改查mapper文件
1.相对应的类中的mapper.xml操作(需要注意的是在文件声明的时候需要声明是mapper,否则会出现问题。)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.example.springboot.dao.UserMapper">
<select id="queryUserByUserName" parameterType="string" resultType="org.example.springboot.po.User">
select
id,user_name,user_pwd
from
tb_user
where
user_name=#{userName}
</select>
<!-- 通过用户id进行查询 -->
<select id="queryById" parameterType="int" resultType="org.example.springboot.po.User">
select *from tb_user where id=#{id,jdbcType=INTEGER}
</select>
<!-- 添加用户的操作 -->
<insert id="save" parameterType="org.example.springboot.po.User">
insert into tb_user(user_name,user_pwd) values(#{userName},#{userPwd})
</insert>
<!-- 修改用户信息操作 -->
<update id="updateUser" parameterType="org.example.springboot.po.User">
update tb_user set user_name=#{userName},user_pwd=#{userPwd} where id=#{id}
</update>
<!-- 删除用户操作 -->
<delete id="deleteUser" parameterType="int">
delete from tb_user where id=#{id}
</delete>
<!-- 分页查询 -->
<select id="queryUserByParams" parameterType="org.example.springboot.query.UserQuery" resultType="org.example.springboot.po.User">
select *from tb_user
<where>
<if test="null!=userName and userName!=''">
and user_name like concat('%',#{userName},'%')
</if>
</where>
</select>
</mapper>