当前位置:网站首页>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();
}
查询结果
边栏推荐
- OnePlus 10RT appears on Geekbench, product launch also seems to be approaching
- bat 批示处理详解-2
- Use of message template placeholders
- 金鱼哥RHCA回忆录:CL210管理OPENSTACK网络--网络配置选项
- SQL的ROUND函数用法及其实例
- B001 - 基于STM32的智能生态鱼缸
- 暑假第一周总结博客
- 粒子滤波 particle filter —从贝叶斯滤波到粒子滤波——Part-I(贝叶斯滤波)
- B002 - Embedded Elderly Positioning Tracking Monitor
- 突破性能天花板!亚信数据库支撑 10 多亿用户,峰值每秒百万交易
猜你喜欢
随机推荐
Leetcode72. 编辑距离
COS 用户实践征文
opencv语法Mat类型总结
Break the performance ceiling!AsiaInfo database supports more than 1 billion users, with a peak of one million transactions per second
Go iota关键字与枚举类型实现原理是什么
想随时、随地、随心使用数据库的朋友们,全体注意!
如何让固定点的监控设备在EasyCVR平台GIS电子地图上显示地理位置?
Friends who want to use the database anytime, anywhere and as you like, all attention!
国标GB28181协议EasyGBS平台兼容老版本收流端口的功能实现
How many steps does it take to convert an ENS domain name into music?
typora操作手册
顺序表的简单描述及代码的简单实现
123123123123
【Day_10 0428】井字棋
The elder brother of the goldfish RHCA memoirs: CL210 experiment management it network - chapter
How opencv implements image skew correction
【Day_09 0427】走方格的方案数
钳形万用表使用方法,如何测量电压、电流、电阻?
tooltip control
C language theory--a solid foundation for the written test and interview