Mybatis Plus 自定义 SQL

一、在 mapper 层自定义查询方法

java 复制代码
@Mapper
public interface UserTableMapper extends BaseMapper<UserTableEntity> {

    /**
     * 自定义查询方法
     * @param username 用户名
     */
    List<UserTableEntity> selectAllByUsername(@Param("username") String username);
}

@param 传参。

二、在 mapper.xml 文件中写下具体查询内容

一般是在 resoucesmapper 目录下自定义 xml 文件,我这边是 src/main/resources/mapper/UserTableMapper.xml

xml 复制代码
<mapper namespace="com.example.library.mapper.UserTableMapper">

  <sql id="Base_Column">
    id, username, password
  </sql>

  <select id="selectAllByUsername" resultType="com.example.library.entity.UserTableEntity">
    select <include refid = "Base_Column"/>
    from sys_user
    where username = #{username}
  </select>
</mapper>

select id 对应方法名,resultType 是实体类,通过 #{} 使用方法的参数。

相关推荐
qq_297574677 小时前
【实战教程】SpringBoot 集成阿里云短信服务实现验证码发送
spring boot·后端·阿里云
韩立学长9 小时前
【开题答辩实录分享】以《智能大学宿舍管理系统的设计与实现》为例进行选题答辩实录分享
数据库·spring boot·后端
编码者卢布11 小时前
【Azure Storage Account】Azure Table Storage 跨区批量迁移方案
后端·python·flask
她说..14 小时前
策略模式+工厂模式实现审批流(面试问答版)
java·后端·spring·面试·springboot·策略模式·javaee
梦梦代码精15 小时前
开源、免费、可商用:BuildingAI一站式体验报告
开发语言·前端·数据结构·人工智能·后端·开源·知识图谱
李慕婉学姐16 小时前
【开题答辩过程】以《基于Spring Boot的疗养院理疗管理系统的设计与实现》为例,不知道这个选题怎么做的,不知道这个选题怎么开题答辩的可以进来看看
java·spring boot·后端
tb_first16 小时前
SSM速通2
java·javascript·后端
一路向北⁢16 小时前
Spring Boot 3 整合 SSE (Server-Sent Events) 企业级最佳实践(一)
java·spring boot·后端·sse·通信
风象南16 小时前
JFR:Spring Boot 应用的性能诊断利器
java·spring boot·后端
爱吃山竹的大肚肚16 小时前
微服务间通过Feign传输文件,处理MultipartFile类型
java·spring boot·后端·spring cloud·微服务