溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Service類怎么用

發(fā)布時間:2022-01-19 16:28:59 來源:億速云 閱讀:116 作者:iii 欄目:開發(fā)技術(shù)

這篇“Service類怎么用”文章的知識點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“Service類怎么用”文章吧。

Service用于處理業(yè)務(wù)邏輯和調(diào)用DAO操作數(shù)據(jù)庫。

配置文件

系統(tǒng)的Service在com.jspxcms.core.ContextConfig的@ComponentScan({"com.jspxcms.core.service.impl", "com.jspxcms.ext.service.impl"})配置。

本例的Service在com.jspxcms.plug.ContextConfig的@ComponentScan({ "com.jspxcms.plug.service.impl"})配置。

Service類

package com.jspxcms.plug.service.impl;

@Service
@Transactional(readOnly = true)
public class ResumeServiceImpl implements ResumeService {
    public Page<Resume> findAll(Integer siteId, Map<String, String[]> params,
            Pageable pageable) {
        return dao.findAll(spec(siteId, params), pageable);
    }

    public RowSide<Resume> findSide(Integer siteId,Map<String, String[]> params,
    Resume bean, Integer position, Sort sort) {
        if (position == null) {
            return new RowSide<Resume>();
        }
        Limitable limit = RowSide.limitable(position, sort);
        List<Resume> list = dao.findAll(spec(siteId, params), limit);
        return RowSide.create(list, bean);
    }

    private Specification<Resume> spec(final Integer siteId,
            Map<String, String[]> params) {
        Collection<SearchFilter> filters = SearchFilter.parse(params).values();
        final Specification<Resume> fsp = SearchFilter.spec(filters, Resume.class);
        Specification<Resume> sp = new Specification<Resume>() {
            public Predicate toPredicate(Root<Resume> root,
                    CriteriaQuery<?> query, CriteriaBuilder cb) {
                Predicate pred = fsp.toPredicate(root, query, cb);
                if (siteId != null) {
                    pred = cb.and(pred, cb.equal(root.get("site")
                            .<Integer> get("id"), siteId));
                }
                return pred;
            }
        };
        return sp;
    }

    private ResumeDao dao;

    @Autowired
    public void setDao(ResumeDao dao) {
        this.dao = dao;
    }
}

該類使用到JPA的Specification查詢方式??蓪?shí)現(xiàn)后臺列表點(diǎn)擊表頭,按任意列排序;列表頁按任意字段查詢;編輯頁面上一條、下一條功能。

以上就是關(guān)于“Service類怎么用”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI