当前位置:网站首页>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();
}
查询结果

边栏推荐
猜你喜欢

粒子滤波 particle filter —从贝叶斯滤波到粒子滤波——Part-I(贝叶斯滤波)

ExcelPatternTool: Excel表格-数据库互导工具

QT_QThread thread

8月微软技术课程,欢迎参与

opencv syntax Mat type summary

【Day_09 0427】走方格的方案数

QLineEdit learning and use

亚马逊云科技Build On2022技能提升计划第二季——揭秘出海爆款新物种背后的黑科技

B002 - Embedded Elderly Positioning Tracking Monitor

Leetcode72. Edit Distance
随机推荐
B005 - STC8 based single chip microcomputer intelligent street light control system
Golang协程调度器scheduler怎么使用
LeetCode 1374.生成每种字符都是奇数个的字符串
JVM运行时数据区与JMM内存模型是什么
1065 A+B and C (64bit)
tooltip control
【Day_09 0427】走方格的方案数
Leetcode71. 简化路径
电商库存系统的防超卖和高并发扣减方案
WinRAR | 将多个安装程序生成一个安装程序
粒子滤波 particle filter —从贝叶斯滤波到粒子滤波——Part-I(贝叶斯滤波)
Tower Defense Shoreline User Agreement
【Day_12 0507】查找组成一个偶数最接近的两个素数
The function realization of the national standard GB28181 protocol EasyGBS platform compatible with the old version of the inflow port
opencv如何实现图像倾斜校正
Live chat system technology (8) : vivo live IM message module architecture practice in the system
QT_QDialog dialog
explain 各字段介绍
亚马逊云科技Build On2022技能提升计划第二季——揭秘出海爆款新物种背后的黑科技
三种方案解决:npm WARN config global --global, --local are deprecated. Use --location=global instead.