这篇“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"})配置。
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类怎么用”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。