java8新特性使用 如stream流;时间区间和模糊查询;数据源yml

282 阅读1分钟

java8 stream

userList = userList.stream().sorted(Comparator.comparing(UserDTO::getAge)).collect(Collectors.toList());


filter 过滤 如stream().filter()
map
sorted 排序
limit 限制几个
filter()和map()的区别:
filter是过滤操作,返回结果为true的数据;而map的作用是将流中的每一个元素T映射为R。
Java8新特性 Stream简介 stream().filter和stream().map区别

Java stream()用法集合单独取出对象中一个属性成为集合或数组

List<DictEntity> dictEntityList = dictService.findByType(6);


List<String> stateNameList = dictEntityList.stream().map(DictEntity::getName).collect(Collectors.toList());


时间区间和模糊查询

时间区间

<if test="query.showStartTime != null and query.showStartTime != ''">
            and gmt_create &gt;= #{query.showStartTime}
        </if>
        <if test="query.showEndTime != null and query.showEndTime != ''">
            and gmt_create &lt;= #{query.showEndTime}
        </if>


模糊查询

        <if test="query.brandName != null and query.brandName != ''">
            and brand_name like CONCAT('%',#{query.brandName},'%')
        </if>


数据源yml

数据源yml
hikari
“史上最快连接池”,后面配置连接池
#此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
max-lifetime: 20000

#数据库连接超时时间,默认30秒,即30000
connection-timeout: 30000
connection-test-query: SELECT 1

默认数据源HikariDataSource
type: com.zaxxer.hikari.HikariDataSource

driver-class-name

redis
redis:
host: 地址
port: 端口
database: 3

rocketmq
rocketmq:
nameServer: 服务器地址
acl:
accesskey: 公钥
accessSecret: 秘钥

本文使用 文章同步助手 同步