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

相关推荐

不愿透露姓名的神秘牛友
07-10 12:05
点赞 评论 收藏
分享
牛客73617529...:无端端被你骂一句
点赞 评论 收藏
分享
06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
06-07 17:17
嘉兴学院 教师
单单人旁的佳:你是我见过最美的牛客女孩
点赞 评论 收藏
分享
07-14 12:29
门头沟学院 Java
后端岗,实习三周感觉有点想跑路了,担心秋招被拉黑,有没有佬是字节HR知道情况的
从零开始的转码生活:你实习三周都想跑路,将来拿到offer真的愿意在这干十几二十年吗
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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