Spring boot实现模糊查询
来源:互联网 发布:sql中的isnull函数 编辑:程序博客网 时间:2024/05/19 09:39
使用注解方式
记得查询时要加通配符来表示个数等信息!
参考博文,SQL模糊查询语句
SearchController.java
package cn.shop.controller;import cn.shop.entity.Shoe;import cn.shop.service.ProductService;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody;import java.util.List;@Controller@RequestMapping(value = "search")public class SearchController { private Logger logger = LoggerFactory.getLogger(SearchController.class); @Autowired private ProductService productService; @RequestMapping(value = "") @ResponseBody public List<Shoe> showSearch(@RequestParam(value = "key") String key , Model model){ logger.info("key:" + key); List<Shoe> list = productService.searchShoes(key); logger.info("查询结果个数:" + list.size()); return list; }}
ProductService.java
package cn.shop.service;import cn.shop.entity.Shoe;import cn.shop.repository.ProductRepository;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.List;@Servicepublic class ProductService { @Autowired private ProductRepository productRepository; public List<Shoe> searchShoes(String key){ //记得加 % % return productRepository.findAllByNameLike("%" + key + "%"); }}
ProductRepository.java
package cn.shop.repository;import cn.shop.entity.Shoe;import org.springframework.data.jpa.repository.JpaRepository;import org.springframework.data.repository.query.Param;import java.util.List;public interface ProductRepository extends JpaRepository<Shoe,Integer>{ public List<Shoe> findAllByNameLike(String key);}
阅读全文
1 0
- Spring boot实现模糊查询
- 1、Spring Boot 模糊查询
- spring-mybatis实现简单模糊查询
- spring 模糊查询,查询
- spring mongo模糊查询
- spring mongodb 模糊查询
- spring jpa 模糊查询
- 实现WINFORM模糊查询
- DropDownList 实现模糊查询
- sphinx实现模糊查询
- List<> 实现模糊查询
- jQuery实现模糊查询
- UITextField实现模糊查询
- HQL实现模糊查询
- mybatis模糊查询实现
- Nodejs实现模糊查询
- 过滤器实现模糊查询
- Spring Data MongoDB 模糊查询
- SQL update 语句
- SpringBoot学习笔记
- 简单工程模式
- Java Jedis操作Redis示例(一)——pub/sub模式实现消息队列
- 用poi插件完成导出Excel导出(通用方法)
- Spring boot实现模糊查询
- CSS 图片偏移技术以及坐标问题
- sql server 截取日期
- vue中使用stylus
- android APK包名和启动的Activity
- html语言代码表
- 思维导图全解析——高大上导图必备基础
- PMP备考【终结篇】从报考培训班到pmp考试结束,整个时间点
- QT5 bug