欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java常用小知识点(一)

程序员文章站 2022-07-14 11:10:39
...

1、实体类存在但数据库中不存在

@TableField(exist = false)
private String testName;

2、String类型拼接

StringJoiner joinStr= new StringJoiner(",");
joinStr.add("1234");
joinStr.add("5678");
System.out.println(joinStr.toString());;

Java常用小知识点(一)

3、数组转List

ArrayList<String> list = new ArrayList<String>(Arrays.asList(strArray)) ;

4、updateAllColumnById和updateById的区别

updateById方法在更新时,会根据实体类的每个属性进行非空判断,只有非空的属性所对应的字段才会出现在SQL语句中。
updateAllColumnById方法在插入时,不管属性是否为空,属性所对应的字段都会出现在SQL语句中

5、切割数组

SQLserver查询的时候,若参数过长,会报错,此时可以使用切割数据的方法,将大数据量切开,再小批量使用

Lists.partition(dataList, 100)
//这个的意思是按100切,假设有1000条,就会分为10个集合

6、用一个数据生成list

 List<String> strList =  Collections.singletonList("123");
 System.out.println(strList);

Java常用小知识点(一)

7、DAO的XML中使用map

<update id="updateEmp" parameterType="java.util.Map">
  <foreach item="no" index="teacherId" collection="dataMap.entrySet()" separator=";">
      update teacher
      set no= #{no}
      where id= #{teacherId} and is_delete = 0
  </foreach>
</update>

持续更新中…