1.orderCotroller
1)表单验证类 items字符串?
2)@Valid @ 及报错的处理
3)返回对象的选用
4)json字符串参数转换成list
Gson
<!--gson处理json字符-->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
orderDetailList=gson.fromJson(orderForm.getItems(),new TypeToken<List>(){}.getType());
package com.scbg.converter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.scbg.dataobject.OrderDetail;
import com.scbg.dto.OrderDTO;
import com.scbg.enums.ResultEnum;
import com.scbg.exception.SellException;
import com.scbg.form.OrderForm;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
/**
* @program: sell
* @description: 表单验证对象和订单传输对象转换
* @author: 三层饼干儿
* @create: 2019-08-12 21:03
**/
@Slf4j
public class OrderForm2OrderDTOConverter {
public static OrderDTO convert(OrderForm orderForm){
Gson gson = new Gson();
OrderDTO orderDTO= new OrderDTO();
orderDTO.setBuyerName(orderForm.getName());
orderDTO.setBuyerPhone(orderForm.getPhone());
orderDTO.setBuyerAddress(orderForm.getAddress());
orderDTO.setBuyerOpenid(orderForm.getOpenid());
List<OrderDetail> orderDetailList= new ArrayList<>();
try {
orderDetailList=gson.fromJson(orderForm.getItems(),new TypeToken<List<OrderDetail>>(){}.getType());
}catch (Exception e){
log.error("【对象转换】错误,string={}",orderForm.getItems());
throw new SellException(ResultEnum.PARAM_ERROR);
}
orderDTO.setOrderDetailList(orderDetailList);
return orderDTO;
}
}
5)postman测试参数加引号,数据库会有引号
6)时间转换
jsonGenerator.writeNumber(date.getTime()/1000);//这特码都转了而且除了1000还要前边干嘛???
吃饱撑的,原来是日期现在一串数字,问下前端兄弟咋整
7)如果前端要求是null就不传加注解在对应数据类体
或者配置文件
8)要空比如“”或者[],就在类中给个默认值