1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 3 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 4 <!-- namespace:表示名称空间。现在的目的是区分id的. --> 5 <mapper namespace="com.zhiyou100.zhl.dao.UsersDao"> 6 <!-- 根据id查询用户。id:标识该标签。 7 parameterType:参数类型。可以写 也可以省略 8 resultType:返回结果的类型。 9 10 #{id}:类似于EL表达式。 解析id的值 11 --> 12 13 <select id="selByAge" parameterType="map" resultType="com.zhiyou100.zhl.bean.Users"> 14 <![CDATA[select * from users where age>=#{min} and age<=#{max}]]> 15 </select> 16 17 <select id="getUser" parameterType="int" resultType="com.zhiyou100.zhl.bean.Users"> 18 select * from users where id=#{id}; 19 </select> 20 21 <insert id="addUser" parameterType="com.zhiyou100.zhl.bean.Users" useGeneratedKeys="true" keyProperty="id"> 22 insert into users(name,age) value(#{name},#{age}); 23 </insert> 24 25 <delete id="delUser" parameterType="int"> 26 delete from users where id=#{id}; 27 </delete> 28 29 <update id="updateUser" parameterType="com.zhiyou100.zhl.bean.Users"> 30 update users set name=#{name},age=#{age} where id=#{id}; 31 </update> 32 33 <select id="selAll" resultType="com.zhiyou100.zhl.bean.Users"> 34 select * from users order by${columnName}; 35 </select> 36 </mapper>
@Test void testAdd() { Users u=new Users("什么",21); usersdao.addUser(u); System.out.println(u.getId()); }