首页 > 其他 > 详细

Mybatis增删改查实现

时间:2021-05-25 12:29:44      阅读:19      评论:0      收藏:0      [点我收藏+]

注意事项:resultType=" " 要写上完整路径(除非有进行相关的配置,才可以仅仅写类的名称)

技术分享图片
<?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.ma.dao.UserMapper">

    <!--映射之后的User&#45;&#45;com.ma.pojo.User-->
   <!-- <select id="getUserList" resultType="hello">-->
    <select id="getUserList" resultType="User">
        select * from mybatis.user
     </select>

    <select id="getUserLike" resultType="com.ma.pojo.User">
        select * from mybatis.user where name like "%"#{value}"%";
    </select>

    <select id="getUserById" parameterType="int" resultType="com.ma.pojo.User">
        select * from mybatis.user where id = #{id};
    </select>
    
    <insert id="addUser" parameterType="com.ma.pojo.User">
        insert into mybatis.user (id, name, pwd) values (#{id},#{name},#{pwd});
    </insert>

   <!-- map用法,可以随意给某赋值,然后其他值不定义-->
    <!--<insert id="addUser2" parameterType="map">
        insert into mybatis.user (id, name, pwd) values (#{userid},#{userName},#{passWord});
    </insert>-->
    
    <update id="updateUser" parameterType="com.ma.pojo.User">
        update mybatis.user set name = #{name}, pwd = #{pwd} where id = #{id};
    </update>

    <delete id="deleteUser" parameterType="int">
        delete from mybatis.user where id =#{id};
    </delete>
    
    <select id="getUserByLimit" parameterType="map" resultType="user">
        select * from mybatis.user limit #{startIndex},#{PageSize};
    </select>
</mapper>
View Code

 

Mybatis增删改查实现

原文:https://www.cnblogs.com/pangbi/p/14807548.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!