mybatis-plus自定义功能

62 阅读1分钟

创建接口:

@Repository
public interface UserMapper extends BaseMapper<User> {
    /*
   根据id查询用户信息,并将用户信息以为map集合的形式返回
     */
    Map<String,Object> selectMapById(Long id);

}

创建文件:

image.png

文件内容:

<?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.demo.Mapper.UserMapper">
<!--    自定义的查询功能,注意这个文件所在文件夹的名字和位置-->

<!--    Map<String,Object> selectMapById(Long id);-->
    <select id="selectMapById" resultType="map">
        select id,name,age,email from user where id=#{id}
    </select>


</mapper>

然后就可以直接使用我们自定义的功能进行数据库中的数据的操作了。