Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the Service class

Shulou Source: shulou.com Published: 2022-06-02 01:28:09 10月23日 Update

Most people do not understand the knowledge points of this article "how to use Service class", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use Service class" article.

Service is used to handle business logic and to invoke DAO to manipulate the database.

Configuration file

The Service of the system is configured in @ ComponentScan ({"com.jspxcms.core.service.impl", "com.jspxcms.ext.service.impl"}) of com.jspxcms.core.ContextConfig.

The Service for this example is configured in @ ComponentScan ({"com.jspxcms.plug.service.impl"}) of com.jspxcms.plug.ContextConfig.

Service class package com.jspxcms.plug.service.impl;@Service@Transactional (readOnly = true) public class ResumeServiceImpl implements ResumeService {public Page findAll (Integer siteId,Map params, Pageable pageable) {return dao.findAll (spec (siteId, params), pageable);} public RowSide findSide (Integer siteId,Map params, Resume bean, Integer position, Sort sort) {if (position = = null) {return new RowSide () } Limitable limit = RowSide.limitable (position, sort); List list = dao.findAll (spec (siteId, params), limit); return RowSide.create (list, bean);} private Specification spec (final Integer siteId, Map params) {Collection filters = SearchFilter.parse (params). Values (); final Specification fsp = SearchFilter.spec (filters, Resume.class) Specification sp = new Specification () {public Predicate toPredicate (Root root, CriteriaQuery query, CriteriaBuilder cb) {Predicate pred = fsp.toPredicate (root, query, cb); if (siteId! = null) {pred = cb.and (pred, cb.equal (root.get ("site"). Get ("id"), siteId);} return pred;}}; return sp;} private ResumeDao dao; @ Autowired public void setDao (ResumeDao dao) {this.dao = dao;}}

This class uses the Specification query method to JPA. The background list can be sorted by any column by clicking on the header, the list page can be queried by any field, and the function of editing one or the next item on the page can be realized.

The above is about the content of this article "how to use the Service class". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Tags: Content configuration articles knowledge articles queries business value functions background most fields that is data databases files methods more steps knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Microsoft Shulou Information vpn Xiaomi