不多说直接上代码!

接口:


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,模糊查询语句,以及传参数的正确写法的更多相关文章

  1. mybatis模糊查询语句

    articletitle like concat('%',#{articletitle},'%')

  2. Ibatis/Mybatis模糊查询

    Ibatis/Mybatis模糊查询 根据网络内容整理 Ibatis中 使用$代替#.此种方法就是去掉了类型检查,使用字符串连接,不过可能会有sql注入风险. Sql代码 select * from ...

  3. 在Delphi中动态地使用SQL查询语句 Adoquery sql 参数 冒号

    在Delphi中动态地使用SQL查询语句 在一般的数据库管理系统中,通常都需要应用SQL查询语句来提高程序的动态特性.下面介绍如何在Delphi中实现这种功能.在Delphi中,使用SQL查询语句的途 ...

  4. mybatis模糊查询sql

    今天下午做的一个功能,要用到模糊查询,字段是description,刚开始我的写法用的是sql中的模糊查询语句, 但是这个有问题,只有将字段的全部值传入其中,才能查询,所以不是迷糊查询. 后来经过搜索 ...

  5. MyBatis模糊查询相关

    Mybatis模糊查询的实现不难,如下实例:在UserMapper.xml中根据用户名模糊查询用户: <!-- 模糊查询用户 --> <select id="findSom ...

  6. ***PHP $_FILES函数详解 + PHP文件上传 move_uploaded_file() 参数的正确写法

    PHP $_FILES函数详解 在PHP中上传一个文件建一个表单要比ASP中灵活得多.具体的看代码. 如:  复制代码代码如下: <form enctype="multipart/fo ...

  7. django ORM 增删改查 模糊查询 字段类型 及参数等

    ORM 相关 #sql中的表 #创建表: CREATE TABLE employee( id INT PRIMARY KEY auto_increment , name VARCHAR (), gen ...

  8. mybatis模糊查询防止SQL注入

    SQL注入,大家都不陌生,是一种常见的攻击方式.攻击者在界面的表单信息或URL上输入一些奇怪的SQL片段(例如“or ‘1’=’1’”这样的语句),有可能入侵参数检验不足的应用程序.所以,在我们的应用 ...

  9. MyBatis 模糊查询的 4 种实现方式

    引言 MyBatis 有 4 种方式可以实现模糊查询. 员工信息表 ( tb_employee ) 如下: id name sex email birthday address 001 张一凡 男 z ...

随机推荐

  1. 索引之----mysql联合索引

    重要概念: 1.对于mysql来说,一条sql中,一个表无论其蕴含的索引有多少,但是有且只用一条. 2.对于多列索引来说(a,b,c)其相当于3个索引(a),(a,b),(a,b,c)3个索引,又由于 ...

  2. Linux hostname 主机名篇

    主机名修改(以主机名为config为例) 1.修改文件/etc/sysconfig/network,内容为 [root@config ~]# cat /etc/sysconfig/network# C ...

  3. Sequential game

    Sequential game Problem Description Sequential detector is a very important device in Hardware exper ...

  4. 搜索专题: HDU1312Red and Black

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. Cleaning Robot (bfs+dfs)

    Cleaning Robot (bfs+dfs) Here, we want to solve path planning for a mobile robot cleaning a rectangu ...

  6. django事务模式

    from django.db import transaction from django.db import transaction with transaction.atomic(): obj = ...

  7. svn版本服务器的搭建和简单使用

    ⼀ 服务器搭建篇 1 在”应⽤用程序”⽂文件夹下,找到”实⽤用⼯工具”,打开”终端”APP 2 运⾏行svnadmin create repository,运⾏行完毕之后,可以在当前⺫⽬目录下找 到⼀ ...

  8. SQL Server 批量 删除表索引

    当旧的数据库中的数据几乎很少使用到的时候,索引又占用着较大的磁盘空间,数据又不能删除,又想节省磁盘空间. 这个时候可以将所有表的索引进行删除了(先创建索引备份脚本,以备需要还原),可以批量一起删除. ...

  9. 编写第一个Qt程序

    http://c.biancheng.net/view/1817.html 学习一种编程语言或编程环境,通常会先编写一个“Hello World”程序.我们也用 Qt Creator 编写一个“Hel ...

  10. i3wm 配置刷新生效 和 使用mod快捷打开 ranger 小贴士

    在某处学习到了如何配置i3wm后,对其极感兴趣. 学习到的经验总结: Linux中的各种命令操作其实都要首先查阅 man command  或者  command -h  或者  command -- ...