注意事项: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--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>
原文:https://www.cnblogs.com/pangbi/p/14807548.html