java各种⼯具类收集,对象属性赋值,jdk1.8特性,json串转换List 1.将⼀个对象的属性值复制给另⼀个对象
铜镀铬2.jdk1.8特性获取类⽬type列表
//获取某⼀属性集合
List<Integer> categoryTypeList = productInfoList.stream()
.map(ProductInfo::getCategoryType)
.List());
//获取对象集合
public List<ProductInfoOutput> findList(List<String> productIdList) {
return productinforepository.findByProductIdIn(productIdList).stream()
.map(e ->{
颤音技巧和发声方法
ProductInfoOutput output = new ProductInfoOutput();
return output;
}).List());
}
3. split ⽤法注意
// \\会转义成反斜杠,反斜杠本⾝就是转义符,所有就成了“\.”,在进⾏转义就是.,所以\\.实际上是“.”
String[] aa = "a.ab.abc".split("\\.");
String cc = "a=1 and b =2 or c=3";
String[] bb =cc.split("and|or"); // |作为连接符
for (int i=0;i<bb.length;i++){
System.out.println(bb[i].replace(" ",""));
}
String[] dd ="2|33|4".split("\\|");
//2 33 4
for (int i=0;i<dd.length;i++){
System.out.println(dd[i].replace(" ",""));
}
4.json 串转换List
le.gson.Gson;
/**
* 2019/10/23 22:30
*/
@Slf4j
//⽅法⼀
public class OrderForm2OrderDTOConverter {
public static OrderDTO convert(OrderForm orderForm){
Gson gson = new Gson();
OrderDTO orderDTO = new OrderDTO();入党条件
orderDTO.Name());
orderDTO.Address());
orderDTO.Address());
orderDTO.Openid());
List<OrderDetail> orderDetails = new ArrayList<>();
try {
//json串编程List
豹子英语orderDetails =gson.Items(),
new TypeToken<List<OrderDetail>>(){}.getType());
}catch (Exception e){
<("[json转换] 错误,String={}",Items());
throw new OrderException(ResultEnum.PARAM_ERROR);
}
orderDTO.tOrderDetailList(orderDetails);
return orderDTO;
}
//⽅法⼆
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
public static void main(String[] args) {
// 转换⽅法1水准仪的使用方法
JSONArray array = JSONArray.fromObject("[{'name':'hehe','age':22}]");
List<Person> list = List(array, Person.class);// ⽅法已过时
System.out.(0).getName());
// 转换⽅法2
List<?> list2 = List(array, new Person(), new JsonConfig());
性单恋者//参数1为要转换的JSONArray数据,参数2为要转换的⽬标数据,即List盛装的数据 Person person = (Person) (0);
System.out.Age());
}
}
/**
* 对象转json
* //将java对象转换为json对象
*/
net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(reply);
String str = String();//将json对象转换为字符串
5. 判断List 是否为空
CollectionUtils.isEmpty(list)
public static boolean isEmpty(@Nullable Collection<?> collection) {
return collection == null || collection.isEmpty();
}
public interface List<E> extends Collection<E> {
}
6.⽣成唯⼀主键
/
**
* ⽣成唯⼀的主键
华严经全文* 格式:时间+随机数
*/
public static synchronized String genUniquekey(){
Random random = new Random();
Integer number = Int(90000)+100000;
return System.currentTimeMillis()+String.valueOf(number);
}
@Override
public String toString(){
StringBuilder res = new StringBuilder();
res.append(String.format("Array:size=%d,capacity =%d\n",size,data.length)); res.append('[');
for (int i=0;i<size;i++){
res.append(data[i]);
if(i!=size-1){
res.append(",");
}
老鹰打饱嗝
}
res.append("]");
String();
}
/
/ format,格式化后,输出如下
//Array:size=10,capacity =20
//[0,1,2,3,4,5,6,7,8,9]
//list 转换String (json形式)
net.sf.json.JSONArray json = net.sf.json.JSONArray.fromObject(questionVOS); String json_str = String();