当前位置:网站首页>Fuzzy query in Map pass-by-value and object pass-by-value
Fuzzy query in Map pass-by-value and object pass-by-value
2022-08-01 18:20:00 【Small and cool】
文章目录
一、在MapFuzzy query in pass-by-value
- 适用于字段或者参数过多,我们应当考虑使用Map!
- 在xml的sql语句当中,parametertaypeThe type of directly writemap,No need to write the full class name of the entity class.
- #{} Variables can be named arbitrarily within parentheses,It is no longer necessary to match the variable name of the entity class.
- 在测试时,只需要 new 一个hashmap ,Treat variables inside parentheses as key值,valuefor the value you want to add,然后put进map里就可以了.Saves the step of building multiple constructors.
1、Mapper接口
List<Map> UserList(Map<String,Object> map);
2、XML
<select id="UserList" resultType="map">
select *
from mybatis01.user where name like #{value};
</select>
3、Test
@Test
public void getUserList() {
SqlSession sqlSession = MybatisUtil.getSqlSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
HashMap<String, Object> map = new HashMap<>();
map.put("value", "%亚%");
List<Map> maps = mapper.UserList(map);
for (Map map1 : maps) {
System.out.println(map1);
}
//In addition, deletion and modification, the transaction must be submitted! sqlSession.commit();
sqlSession.close();
}
二、Fuzzy query in object pass-by-value
- bound to the interfacexml中,#{} 括号里面的变量,Must correspond to the variable name defined by the entity class.
- 在测试类当中,要new对象时,The parameters of the constructor must also correspond one-to-one with the constructor created by the entity class.
1、实体类
package com.jin.pojo;
public class User {
private int id;
private String name;
private String pwd;
...
// (无参、有参、get和set、toString)
...
}
2、Mapper接口
List<User> UserList02(String name);
3、XML
<select id="UserList02" resultType="com.jin.pojo.User" parameterType="String">
select *
from mybatis01.user where name like #{name};
</select>
4、Test
@Test
public void UserList02(){
SqlSession sqlSession = MybatisUtil.getSqlSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
List<User> userList = mapper.UserList02("%亚%");
for (User user : userList) {
System.out.println(user);
}
//In addition, deletion and modification, the transaction must be submitted! sqlSession.commit();
sqlSession.close();
}
查询结果
边栏推荐
- B002 - 基于嵌入式的老人定位追踪监测仪
- WinRAR | Generate multiple installers into one installer
- SQL function TO_DATE (1)
- Go GORM transaction instance analysis
- 将ENS域名转化为音乐需要几步?
- tooltip control
- Three solutions: npm WARN config global --global, --local are deprecated. Use --location=global instead.
- 钳形万用表使用方法,如何测量电压、电流、电阻?
- C#/VB.NET:从 PDF 文档中提取所有表格
- 加州大学|通过图抽象从不同的第三人称视频中进行逆强化学习
猜你喜欢
随机推荐
opencv实时人脸检测
【Day_12 0507】二进制插入
QPalette palette, frame color fill
以消费场景为驱动的CMDB要怎么建?
CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) Solution
el-form-item prop属性动态绑定不生效如何解决
explain 各字段介绍
XML配置
生命周期和作用域
C language theory--a solid foundation for the written test and interview
JVM运行时数据区与JMM内存模型是什么
B002 - Embedded Elderly Positioning Tracking Monitor
在Map传值与对象传值中模糊查询
OnePlus 10RT appears on Geekbench, product launch also seems to be approaching
Go GORM事务实例分析
opencv如何实现图像倾斜校正
2022,程序员应该如何找工作
SQL的substring_index()用法——MySQL字符串截取
How to make the fixed-point monitoring equipment display the geographic location on the EasyCVR platform GIS electronic map?
EpiSci | Deep Reinforcement Learning for SoCs: Myth and Reality