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