1. restTemplate能否传递list集合?
这里要求接口接收Json格式数据
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
String json = SerializeUtil.Serialize(archiveFileList);//可以使用其他工具
HttpEntity<String> formEntity = new HttpEntity<String>(json, headers);
String result = restTemplate.postForObject(url, formEntity, String.class);
2. java.util.LinkedHashMap cannot be cast to 实体类
调用过程中数据类型的变化:服务提供者返回的是LIst集合,但是标记了@RequestBody,所以返回的时候会把List集合转变成json的形式(内部是jackjson技术支持的)
然后服务消费者使用restTemplate.getForObject(),第二个参数传入接受的类型(就是将响应体中内容以什么类型封装)
如果像上面的写法,就会再把提供者返回的json转变成list,但是这个list跟之前不一样(一个是jackjson转变的,一个是restTemplate转变的,可能内部机制不一样)
// 将响应体内容以String格式接受,即json字符串
String json = restTemplate.getForObject("http://SPRINGCLOUD-EMPLOYEE-PROVIDER/emp/list",
String.class);
// 将json字符串转集合
List<EmployeeModel> employeeModels = JSON.parseArray(json, EmployeeModel.class);
//可以利用JSON双向进行转换
3. Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'
http.csrf().disable();
4. Incorrect datetime value: '' for column 'createTime' at row 1
Date nowdate=new Date();
//转换时间格式
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
user.setCreateTime(Timestamp.valueOf(simpleDate.format(nowdate)));
5. 页面静态化