From 9509af69aff71aeb1f3b62f766e124d291c3f374 Mon Sep 17 00:00:00 2001 From: liulin <lin.liu@aliyun.com> Date: 星期二, 30 七月 2024 00:07:04 +0800 Subject: [PATCH] 适配mybatis-plus --- src/main/java/com/lunhan/xxx/repository/imapper/TestInfoMapper.java | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/lunhan/xxx/repository/imapper/TestInfoMapper.java b/src/main/java/com/lunhan/xxx/repository/imapper/TestInfoMapper.java index d11044a..3d49251 100644 --- a/src/main/java/com/lunhan/xxx/repository/imapper/TestInfoMapper.java +++ b/src/main/java/com/lunhan/xxx/repository/imapper/TestInfoMapper.java @@ -1,4 +1,31 @@ package com.lunhan.xxx.repository.imapper; -public interface TestInfoMapper { +import com.baomidou.mybatisplus.core.toolkit.Constants; +import com.lunhan.xxx.entity.dto.search.SearchTestInfo; +import com.lunhan.xxx.repository.BasicMapper; +import com.lunhan.xxx.repository.po.TestInfoPO; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +public interface TestInfoMapper extends BasicMapper<TestInfoPO> { + // #{param}:会进行预编译,而且进行类型匹配,最后进行变量替换,括号中可以添加映射类型如 +// @Select( +// "<script>" + +// "select * from student where id= #{param,javaType=int,jdbcType=NUMERIC}" + +// "</script> " +// ) + // ${param}:$只是只是简单的字符串拼接,要特别小心sql注入问题,对应非变量部分,只能用$。$方式一般用于传入数据库对象,比如这种group by 字段 ,order by 字段,表名,字段名等没法使用占位符的就需要使用${param} + + @Select("select * from test_info where id = #{id}") + TestInfoPO testGet(Long id); + + @Select("select * from test_info where id = #{userName}") + TestInfoPO testGet2(String userName); + + @Select("select * from test_info where status = #{ew.status}") + TestInfoPO testGet3(@Param(Constants.WRAPPER) SearchTestInfo search); + + @Select("select * from test_info where status = #{search.status}") + TestInfoPO testGet4(@Param("search") SearchTestInfo search); + } -- Gitblit v1.9.3