前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >第三节:Activiti6.0——Query的API使用

第三节:Activiti6.0——Query的API使用

作者头像
凡人飞
发布于 2020-09-20 12:23:09
发布于 2020-09-20 12:23:09
1.4K00
代码可运行
举报
文章被收录于专栏:指缝阳光指缝阳光
运行总次数:0
代码可运行

一、概述

介绍:对于数据库的信息都可以使用Query接口提供的方法进行查询。此处介绍Query接口的所有API方法使用。为方便演示,使用的是act_id_group表。以下为:Query的所有方法:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public interface Query<T extends Query<?, ?>, U extends Object> {

  /**
   * 该方法需要在调用orderByXxxx后使用
   */
  T asc();

  /**
   * 该方法需要在调用orderByXxxx后使用
   */
  T desc();

  long count();

  U singleResult();
  
  List<U> list();

  List<U> listPage(int firstResult, int maxResults);
}

二、测试

  1. 首先往act_id_group表中添加数据:ProcessEngine pe = ProcessEngines.getDefaultProcessEngine(); IdentityService is = pe.getIdentityService(); for (int i = 0; i < 10; i++) { Group group = is.newGroup(String.valueOf(i)); group.setName("name_" + i); group.setType("type_" + i); is.saveGroup(group); } //关闭流程引擎 pe.close(); System.exit(0);
  2. 使用list//获取流程引擎 ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); //获取身份服务 IdentityService service = processEngine.getIdentityService(); List<Group> list = service.createGroupQuery().list(); list.forEach(group -> { System.out.println(group.getId() + "\t\t" + group.getName() + "\t\t" + group.getType()); }); //结果: //0 name_0 type_0 //1 name_1 type_1 //2 name_2 type_2 //3 name_3 type_3 //4 name_4 type_4 //5 name_5 type_5 //6 name_6 type_6 //7 name_7 type_7 //8 name_8 type_8 //9 name_9 type_9
  3. 使用ListPage方法,分页查询,跟mysql的limit使用一样List<Group> list = service.createGroupQuery().listPage(1, 4);
  4. 使用asc和des进行升序和降序//升序 List<Group> list1 = service.createGroupQuery().orderByGroupName().asc().list(); //降序 List<Group> list2 = service.createGroupQuery().orderByGroupName().desc().list(); //使用多次排序时,排一次序就指定一次顺序 List<Group> list3 = service.createGroupQuery().orderByGroupName().desc().orderByGroupType().asc().list();
  5. 使用count统计数量long count = service.createGroupQuery().count();
  6. 使用SingleResult查询单个数据//单个数据查询 //如果查询出的数据有多个,会报异常:org.activiti.engine.ActivitiException: Query return 2 results instead of max 1 //groupName是根据name进行过滤 Group group = service.createGroupQuery().groupName("name_2").singleResult();
  7. 使用多条件查询//多条件查询,需满足所有条件 List<Group> list = service.createGroupQuery().groupName("name_2").groupId("2").list();
  8. 使用原生的自定义Sql//使用自定义sql List<Group> list = service.createNativeGroupQuery() .sql("select * from act_id_group where NAME_ = #{name}") .parameter("name", "name_4") .list();
  9. 使用like模糊查询List<Group> list = service.createGroupQuery().groupNameLike("%2").list(); //结果:2 name_2 type_2
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/11/12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、概述
  • 二、测试
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档