码迷,mamicode.com
首页 > 其他好文 > 详细

Mybatis,模糊查询语句,以及传参数的正确写法

时间:2019-01-16 10:21:21      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:let   col   _id   mapper   ping   lse   list   nbsp   模糊   

不多说直接上代码!

 

 

 

 

接口:



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

标签:let   col   _id   mapper   ping   lse   list   nbsp   模糊   

原文地址:https://www.cnblogs.com/nongzihong/p/10275271.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!