<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.lotus.mybatis.mapper.SelectMapper"><!--User getUserById(@Param("id") Integer id);--><selectid="getUserById"resultType="User">select * from t_user where id = #{id}</select><!--List<User> getAllUsers();--><selectid="getAllUsers"resultType="User">select * from t_user</select><!--Integer getCount();--><selectid="getCount"resultType="java.lang.Integer">select count(*) from t_user;</select><!--Map<String,Object> getUserByIdToMap(Integer id);--><selectid="getUserByIdToMap"resultType="map">select * from t_user where id=#{id}</select><!--Map<String,Object> getAllUsersToMap();--><selectid="getAllUsersToMap"resultType="map">select * from t_user</select></mapper>
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.lotus.mybatis.mapper.SQLMapper"><!--List<User> getUserByLike(@Param("username") String username);--><selectid="getUserByLike"resultType="User"><!-- ①必须使用${} --><!-- ①select * from t_user where username like '%${username}%'--><!-- ②select * from t_user where username like concat('%',#{username},'%')-->select * from t_user where username like "%"#{username}"%"</select><!--int deleteMore(@Param("ids") String ids);--><deleteid="deleteMore"><!-- 此处必须使用${} -->delete from t_user where id in (${ids})</delete><!--List<User> getUserByTableName(@Param("tableName") String tableName);--><selectid="getUserByTableName"resultType="User"><!-- 此处必须使用${} -->select * from ${tableName}</select><!--void insertUser(User user);--><!--useGeneratedKeys:设置当前标签中的SQL使用了自增的主键keyProperty:将自增的主键的值赋值给传输到映射文件中参数的某个属性--><insertid="insertUser"useGeneratedKeys="true"keyProperty="id">insert into t_user values(null,#{username},#{password},#{age},#{sex},#{email})</insert></mapper>