实习知识点

1. jpa中需要修改列的话需要写一个sql文件用sql语句修改

2. StringUtils.abbreviate的方法的使用

应用场景:当接收的字符串长度不确定,但是确定是非常长,在打印日志时,只打算打印部分,后半部分使用省略号,就可以用
StringUtils.abbreviate(String str, int maxWidth)这个方法
缩减字符串,用省略号代替省略的部分,
分两种情况

1当str的长度小于maxWidth的,则返回str

2当maxWidth小于4时,抛出IllegalArgumentException异常

例如:

@Column(length = 255)
private String sendError;

public void setSendError(String sendError) {
    this.sendError = StringUtils.abbreviate(sendError, 255);
}

该错误信息为调用接口得返回信息,若不能确定长度按如上操作不会报错

3. Objects.isNull(relation)这种方式用在stream流中  平时使用relation == null 即可

4. 去重可以使用set

Set<String> results = Set.newHashSet();

results.addAll(relations.stream().map(WechatRelationStaff::getWechatId).collect(Collectors.toList()));  注意可以直接使用addAll

5.

使用 == 和 equals() 比较字符串。

String 中 == 比较引用地址是否相同,equals() 比较字符串的内容是否相同:

6. 

Date startDate = DateUtils.dateFormat(
wechatCalendarEvent.getStart(), DateUtils.STANDARD_DATE_FORMAT_YMDHMS);
long startTime = TimeUnit.MILLISECONDS.toSeconds(startDate.getTime());

将以毫秒为单位得时间戳转换为以秒为单位得时间戳

7.

jpa得Repository中所有方法都应该命中索引 

indexes = {@Index(name = "index_corpId_wechatId", columnList = "corpId,wechatId")}
@Modifying
int deleteByCorpIdAndWechatId(String corpId, String wechatId);

   通过 @Modifying 注解可以完成修改(UPDATE或者DELETE)操作(注意:不支持新增)

@Query(value = "select * from tab_wechat_relation_staff t where t.corpId = :corpId and t.wechatId = :wechatId " +
            "order by createdAt desc limit 1", nativeQuery = true)
    WechatRelationStaff findByCorpIdAndWechatId(@Param("corpId") String corpId, @Param("wechatId") String wechatId);

注意这种格式
注意更新和删除必须添加@Modifying
nativeQuery表示用原生的sql语句查询  
注意这种形式t.corpId = :corpId   需要对应到@Param("corpId") String corpId 

8.两个list中依据某个属性作匹配  并给其中一个list赋值

Map<String, HardwareCheckInData> hardwareUserMap = hardwareCheckinData.stream()
        .collect(Collectors.toMap(data -> data.getCheckinTime() + "_" + data.getUserId(), Function.identity(), (v1, v2) -> v1));

Function.identity(): 返回本身

(v1, v2) -> v1):  如果v1,v2 key一样以v1得key和value为准

needMatchData.stream()
        .forEach(checkInData -> {
            HardwareCheckInData hardware = hardwareUserMap.get(checkInData.getCheckinTime() + "_" + checkInData.getUserId());
            if (hardware != null) {
                checkInData.setLocationDetail(hardware.getDeviceName());
            }
        });

 9 .@JsonIgnoreProperties(ignoreUnknown = true)

如果接口的返回值比接收类的属性多  加上这个注解不会报错

10. StringUtils.defaultIfEmpty(str , defaultStr) 

str空就defaultStr  否则就str

11.@valued

@Value("${ihr360.message.center.staff.topic:TID_MESSAGE_CENTER_REMIND_EVENT}")

当能从application.properties中找到ihr360.message.center.staff.topic就用他的值  

找不到就用后面: 给赋得值

12. == null  和 isEmpty 不一样

null就是等于null   null不等于"" 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值