Mybatis,模糊查询语句,以及传参数的正确写法
不多说直接上代码!
接口:
public interface CommodityMapper {
int deleteByPrimaryKey(Integer productId);
int insert(Commodity record);
Commodity selectByPrimaryKey(Integer productId);
List<Commodity> selectAll();
List<Commodity> getType(int id);
int updateByPrimaryKey(Commodity record);
int getCount();
List<Commodity> SearchCommodity(@Param("productName") String productName);//注意传参的名字必须要和Mapper文件一致
}
Constroller层:
//搜索
@RequestMapping(path = "/search", method = RequestMethod.GET)
public ResponseEntity Search(String productName) {
if (commodityService.SearchCommodity(productName).size() != 0) {
return ResponseEntity.ok(commodityService.SearchCommodity(productName));
} else {
return ResponseEntity.ok("error");
} }
Mapper文件
<select id="SearchCommodity" resultType="string" resultMap="BaseResultMap">
select
c.product_id,
c.product_name,
c.product_content,
s.product_specs,
s.product_price,
d.product_simg
from commodity c
cross join Standard s
on c.product_id=s.product_id
cross join dommodityAttribute d
on c.product_id=d.product_id
where c.product_name like concat('%',#{productName},'%') group by c.product_id
</select>
Mybatis,模糊查询语句,以及传参数的正确写法的更多相关文章
- mybatis模糊查询语句
articletitle like concat('%',#{articletitle},'%')
- Ibatis/Mybatis模糊查询
Ibatis/Mybatis模糊查询 根据网络内容整理 Ibatis中 使用$代替#.此种方法就是去掉了类型检查,使用字符串连接,不过可能会有sql注入风险. Sql代码 select * from ...
- 在Delphi中动态地使用SQL查询语句 Adoquery sql 参数 冒号
在Delphi中动态地使用SQL查询语句 在一般的数据库管理系统中,通常都需要应用SQL查询语句来提高程序的动态特性.下面介绍如何在Delphi中实现这种功能.在Delphi中,使用SQL查询语句的途 ...
- mybatis模糊查询sql
今天下午做的一个功能,要用到模糊查询,字段是description,刚开始我的写法用的是sql中的模糊查询语句, 但是这个有问题,只有将字段的全部值传入其中,才能查询,所以不是迷糊查询. 后来经过搜索 ...
- MyBatis模糊查询相关
Mybatis模糊查询的实现不难,如下实例:在UserMapper.xml中根据用户名模糊查询用户: <!-- 模糊查询用户 --> <select id="findSom ...
- ***PHP $_FILES函数详解 + PHP文件上传 move_uploaded_file() 参数的正确写法
PHP $_FILES函数详解 在PHP中上传一个文件建一个表单要比ASP中灵活得多.具体的看代码. 如: 复制代码代码如下: <form enctype="multipart/fo ...
- django ORM 增删改查 模糊查询 字段类型 及参数等
ORM 相关 #sql中的表 #创建表: CREATE TABLE employee( id INT PRIMARY KEY auto_increment , name VARCHAR (), gen ...
- mybatis模糊查询防止SQL注入
SQL注入,大家都不陌生,是一种常见的攻击方式.攻击者在界面的表单信息或URL上输入一些奇怪的SQL片段(例如“or ‘1’=’1’”这样的语句),有可能入侵参数检验不足的应用程序.所以,在我们的应用 ...
- MyBatis 模糊查询的 4 种实现方式
引言 MyBatis 有 4 种方式可以实现模糊查询. 员工信息表 ( tb_employee ) 如下: id name sex email birthday address 001 张一凡 男 z ...
随机推荐
- 【转】sql server数据收集和监控
转自:https://www.cnblogs.com/zhijianliutang/p/4476403.html 相关系列: https://www.cnblogs.com/zhijianliutan ...
- SpringMVC框架 课程笔记
SpringMVC框架 课程笔记 第0章 SpringMVC框架的核心内容 1.SpringMVC 概述 2.SpringMVC 的 HelloWorld 3.使用 @RequestMapping 映 ...
- Luogu P2168 [NOI2015]荷马史诗
题目 哈夫曼树的每个叶子结点都有一个权值(表示某数据的出现频率),且\(\sum dis_ival_i\)最小. 哈夫曼树中,权值和越大的集合离根节点越近. 而每个数据对应从根节点到该叶子结点的一种编 ...
- RabbitMq学习3-工作队列(Work queues)
工作队列(又称:任务队列——Task Queues)是为了避免等待一些占用大量资源.时间的操作.当我们把任务(Task)当作消息发送到队列中,一个运行在后台的工作者(worker)进程就会取出任务然后 ...
- c++ Socket客户端和服务端示例版本二
客户端 #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/soc ...
- jupyter notebook添加环境
列出当前kernel: jupyter kernelspec list 删除已有环境:jupyter kernelspec remove NAME 安装新kernel ipython kernel i ...
- c语言之ascii字符
int main(){ char buf[20] = {104,101,108,108,111,0}; printf("buf:%s\n",buf); return 0;} 打印结 ...
- adam优化
AdaGrad (Adaptive Gradient,自适应梯度) 对每个不同的参数调整不同的学习率, 对频繁变化的参数以更小的步长进行更新,而稀疏的参数以更大的步长进行更新. gt表示第t时间步的梯 ...
- 浅谈C++ allocator内存管理(对比new的局限性)(转)
STL中,对内存管理的alloc的设计,迫使我去学习了allocator类.这里对allocator内存管理做了点笔记留给自己后续查阅.allocator类声明.定义于头文件<memory> ...
- "Host 'onlyyou-bridal.jp' is blocked because of many connection errors; unblock with 'mysqladminlush-hosts'"
错误链接数太多 ,清理mysqladminlush-hosts 这个文件 直接 service mysqld restart 解决了~~~ ccess denied for user 'root'@ ...