Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the syntax format of JPA like fuzzy query

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the syntax format of JPA like fuzzy query". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what the syntax format of JPA like fuzzy query is".

JPA like fuzzy query syntax format public List getAllInstitution (final Application app) {String zdGljg = null; Sysuser user = (Sysuser) app.getUser (); String userGljg = user.getGljg () If ("00" .equals (userGljg.substring (4,6) {/ / municipal authority zdGljg = userGljg.substring (0,4) + "%";} else if ("00" .equals (userGljg.substring (6,8) {/ / district and county authority zdGljg = userGljg.substring (0,6) + "%" } else {/ / authority of township institutions zdGljg = userGljg + "%";} Query query = entityManager.createQuery ("select s from InstitutionInfo s where s.gljg like: zdGlbh"); query.setParameter ("zdGlbh", zdGljg); List adg = query.getResultList (); return adg Fuzzy query: how does Spring Data JPA perform fuzzy query (LIKE)?

Spring MVC + Spring Data JPA+ fuzzy query

For convenience, service ignores it directly and makes it easy to understand.

one。 Method one

1. Controller layer:

The method parameters are as follows. Be sure to add "%" + name+ "%".

/ * * @ description: * @ author: czx * @ date: 5:15 on 2018-1-22 * @ version: V1.0 * / @ RestControllerpublic class UserController {@ Autowired private TeamRepository teamRepository; @ GetMapping ("/ findByNameLike") public List findByNameLike (String name) {/ / be sure to add "%" + parameter name + "%" return teamRepository.findByNameLike ("%" + name+ "%");}}

2. Dao layer:

Be sure to use the form findBy+ parameter name + Like (parameter) specified by JPA

/ * * @ description: data layer * @ author: czx * @ date: 10:52 * @ version on 2018-1-18: V1.0 * / public interface TeamRepository extends JpaRepository {List findByNameLike (String name); II. Method two

1. Controller:

Parameter simplification

/ * @ description: * @ author: czx * @ date: 5:15 on 2018-1-22 * @ version: V1.0 * / @ RestControllerpublic class UserController {@ Autowired private TeamRepository teamRepository; @ GetMapping ("/ findByNameLike") public List findByNameLike (String name) {return teamRepository.findByNameLike (name);}}

2.Dao layer:

You need to define your own SQL statements.

/ * @ description: * @ author: czx * @ date: 10:52 * @ version on 2018-1-18 * @ version: V1.0 * / public interface TeamRepository extends JpaRepository {@ Query (value = "select t from Team t where t.name like%? 1%") List findByNameLike (String name); now that you have a better understanding of "what the syntax format of JPA like fuzzy query is", you might as well do it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report