Service类怎么用

发布时间:2022-01-19 16:28:59 作者:iii
来源:亿速云 阅读:103

这篇“Service类怎么用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Service类怎么用”文章吧。

Service用于处理业务逻辑和调用DAO操作数据库。

配置文件

系统的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查询方式。可实现后台列表点击表头,按任意列排序;列表页按任意字段查询;编辑页面上一条、下一条功能。

以上就是关于“Service类怎么用”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。

推荐阅读:
  1. 安卓中Service组件怎么用
  2. Android中Service怎么用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

service

上一篇:安全框架Shiro怎么配置

下一篇:微信小程序中相机组件控制wx.createCameraContext怎么用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》