不多说直接上代码!

接口:


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. spring @Value 获取配置文件为 null 常见的几种方式

    第一种方式: xx.properties 属性名称错误,未与@Value("${xxx}") 进行对应 第二种方式: 该类未注入到spring bean容器中 @Component ...

  2. CentOS7 源进源出

    echo 200 ct >> /etc/iproute2/rt_tablesecho 201 cu >> /etc/iproute2/rt_tables ip route ad ...

  3. JGit、SvnKit - 版本提交日志(1)提取

    1.相关开源jar包  1>使用JGIT访问git项目  2>使用SVNkit访问svn Git官方JGit使用教程指导 2.Git历史提交日志导出到文件 在项目根目录执行如下命令,将日志 ...

  4. http协议是无状态协议,它的无状态指的是什么,如何解决这种情况

    http是无状态的协议,也是不安全的协议, 它的无状态是指对于事务处理没有记忆能力,缺少状态意味着后续的操作需要前面的信息. 解决办法:1,通过cookie解决,2,通过session会话保存.

  5. [七月挑选]使用idea创建spring boot 项目

    title: 使用idea创建spring boot 项目 参考lindaZ的IntelliJ IDEA 创建spring boot 的Hello World 项目 1.Open IDEA,choos ...

  6. docker配置Nginx

    创建及进入docker容器$docker run -p 80 --name web01 -i -t ubuntu /bin/bash 创建html文件夹$mkdir -p /var/www/html ...

  7. MFC学习笔记3---使对话框风格与系统统一

    有一件郁闷了我很久的事情,在VS中编辑对话框或者点击预览时都是以Win7风格体现的按钮及对话框: 点击上图测试对话框: 然而生成的应用程序却是这样的: 这样人很不爽啊,按钮风格回到了N年前的版本,复古 ...

  8. ubuntu安装软件失败

    Unable to fetch some archives, maybe run apt-get update or try with --fix-missing sudo gedit /etc/ho ...

  9. jenkins上job误删除怎么恢复

    1.点击jobConfigHistory 2.点击Show deleted jobs only 3.找到被删除的 记录,点击Restore

  10. Proxy + Reflect 实现 响应的数据变化

    Proxy 对象用于定义基本操作的自定义行为(如属性查找,赋值,枚举,函数调用等) let p = new Proxy(target, handler); get(target, propKey, r ...