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>
全部评论

相关推荐

昨天 16:38
中南大学 营销
点赞 评论 收藏
分享
真的很糟糕:不一定是你的问题,当然你也可以做的更好一些,继续投相信自己一定会有的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务