MybatisPlus学习-添加额外的SQL查询


说明

与mybatis原本的SQL查询相似,通过mapper类,mapper.xml添加

在自己写的mapper接口中添加方法

@Repository
public interface UserMapper extends BaseMapper<User> {

    public User selectByUserName(String username);
}

编写mapper.xml文件

<?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.gui.mapper.UserMapper">

    <select id="selectByUserName" resultType="com.gui.pojo.User">
        select * from user where username = #{username}
    </select>


</mapper>

在配置文件application中的添加mapper.xml的路径

mybatis-plus.mapper-locations=classpath:mapper/*.xml

测试使用


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM