公司实习常用


查看当前git配置

git config --global --list

修改用户名和公司账号

git config --global user.name "sunpengxiang"

git config --global user.email sunpx@mashang.cn


 解除token验证-用于测试接口?devKey=VXiao


 由于公司代码多采用java8流式编程风格,故复习常用java8新特性

stream 排序、过滤、类型转换

// 根据年龄排序
Stream sorted = list.stream().sorted(Comparator.comparing(Student::getAge));
sorted.forEach(student -> {
System.out.println(student.getAge());
});
//根据年龄排序并过滤掉等于20的student
Stream sorted = list.stream().filter(student -> student.getAge() != 20).sorted(Comparator.comparing(Student::getAge));
//根据年龄排序并过滤掉等于20的是student,结果集转换为list
List studentList = list.stream().filter(student -> student.getAge() != 20).sorted(Comparator.comparing(Student::getAge)).collect(Collectors.toList());
//利用map获取所有学生年龄
list.stream().map(Student::getAge).collect(Collectors.toList()).forEach(v -> {
System.out.println(v);
});

Optional.ofNullable的使用
// 判断stundent的id是否为null,如果不是null则添加至list
Optional.ofNullable(student1.getId()).ifPresent(v -> {
list.add(student1);
});
list.add(student2);
list.stream().forEach(l -> {
System.out.println(l.getName());
});
//如果id为空则pId=0L,否则pId=parentId,该方法可有效避免空指针
Long pId = Optional.ofNullable(parentId).orElse(0L);
// 获取student姓名
Optional.ofNullable(student1).map(Student::getName).orElse("no name");
// 获取student姓名的长度
Optional.ofNullable(student1.getName()).map(String::length).orElse(0);

 import org.apache.commons.collections.CollectionUtils;
CollectionUtils的使用
CollectionUtils.isEmpty 判断集合是否为空

mapping层
主要用于DTO对象和ENTITY对象的转换

handler 层 数据格式校验和service依赖解耦

相关