代码篇
如果要随机产生一个a到b(包括a和b)之间的整数,可以使用下面的公式:
int num = (int)( Math.random() * ( b – a + 1 )) + a;
// 随机产生一个a到b(包括a和b)之间的整数
int a = 0;
int b = 10;
int num = (int) ((Math.random()*Math.abs(a-b))+Math.min(a,b));
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
//计算 List 集合中,所有元素的和
int total = list.stream().map(item -> item).reduce((sum, n) -> sum + n).get();//total=6
#将list中所有POJO属性set新值
pojoList.forEach(x -> x.setNeedStocktake(1));
// 获取java.util.List<T> 范型类型
System.out.println(list.get(0).getClass());// com.ljheee.mail.MonitorPO
Object obj = list.get(0);//MonitorPO
Field[] declaredFields = obj.getClass().getDeclaredFields();
declaredFields[0].setAccessible(true);//orderId
System.out.println(declaredFields[0].get(obj));//获取orderId字段值
//数组逆转
public void reverse(char[] arr, int begin, int end) {
while(end > begin) {
char temp = arr[begin];
arr[begin] = arr[end];
arr[end] = temp;
begin++;
end--;
}
}
int a[] = new int[]{1, 2, 3, 4, 5, 6, 7, 8};
//经典洗牌算法
public static void shuffle(int[] a) {
Random random = new Random();
int n = a.length;
for (int i = n - 1; i >= 1; i--) {
int temp = a[i];
int j = random.nextInt(n);
a[i] = a[j];
a[j] = temp;
// swap(a[i],a[j])
}
}
命令使用篇
#git结合Linux下awk命令,统计[指定author]git提交代码行数
#该命令在.git目录下运行;更换author即可。去掉--author参数,则统计整个项目代码行
MacBook-Pro% git log --author="lijianhua" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -
added lines: 39, removed lines: 39, total lines: 0
配置文件篇
<!-- mybatis-config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 分布式应用必须禁用查询缓存 -->
<setting name="cacheEnabled" value="false"/>
<!-- 禁用懒加载-->
<setting name="lazyLoadingEnabled" value="false"/>
<!-- 默认执行超时时间(秒) -->
<setting name="defaultStatementTimeout" value="180"/>
<!-- 下划线命名转驼峰命名-->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!-- 默认开启“获取插入自增主键的值”(仅insert语句) -->
<setting name="useGeneratedKeys" value="true"/>
<setting name="logImpl" value="LOG4J2"/>
</settings>
</configuration>