我是靠谱客的博主 魔幻酸奶,这篇文章主要介绍groovy&&集合 list,现在分享给大家,希望可以做个参考。

一前一直没使用过groovy语言,但是在新的公司需要用到这个语言;不过还好,groovy是基于java之上的语言;学起来不是很吃力;
会一直更新新这篇文章。。。。。
刚开始的时候看到一个符号“<<”

复制代码
1
2
3
4
5
6
7
8
List<Byte> types = Lists.newArrayList() if (type == 3) { types << (1 as byte) types << (2 as byte) } else { types << (byte) type }

一开始很不理解,这不是按位运算符吗;啥意思啊我天;然后自己试了试:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class SymbolDemo { static void main(String[] args) { def i = methdod01(2) println(i) } static def methdod01(Integer a){ Integer type = 3 List<Integer> list = Lists.newArrayList(); list << 1 list << 2 list << 3 if (a == 2){ list << a }else { list << 5 } } }

看到这些代码应该就很明确了。这相当于list.add
在这里插入图片描述需求是这样的一张图片;就是说需要从数据库中查书数据来,然后根据bug status(状态分组);

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
List<BugStatusFindVo> bugStatusFindVos = Lists.newArrayList() List<Bug> bugs = bugService.findBugList(status, systemId, timeType, startTime, endTime) bugs.each { Bug bug -> bugStatusFindVos.each { BugStatusFindVo statusFindVo -> if (bug.status == statusFindVo.status){ statusFindVo.bugs << bug } } } bugStatusFindVos.each { it.bugNum = it.bugs.size() }

BugStatusFindVo :实体类是这样的:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class BugStatusFindVo implements Serializable{ private static final long serialVersionUID = 8401342664443969084L Long bugNum Byte status String statusName List<Bug> bugs = Lists.newArrayList() }

最后

以上就是魔幻酸奶最近收集整理的关于groovy&&集合 list的全部内容,更多相关groovy&&集合内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(63)

评论列表共有 0 条评论

立即
投稿
返回
顶部