Spring Boot学习扎要2_2019.2.11-基于新版本微服务时代Spring Boot企业微信点餐系统

1.

Inferred type 'S' for type parameter 'S' is not within its bound
springboot报错内容:
Inferred type ‘S’ for type parameter ‘S’ is not within its bound; should extends xxxxxx

/*

* 根据id查询
*/
@GetMapping("/student/{id}")
public Student findById(@PathVariable("id") Integer id){
return studentRespository.findOne(id);
}
用以上方法findOne(id);报错,经过网上查询资料最后找到原因。解决办法如下,
1、springboot 版本问题,将 2.0.1 版本换成 1.5.4 版本。
2、将studentRespository.findOne(id); 改为 studentRespository.findById(id).orElse(null);
3、将studentRespository.findOne(id); 改为
return studentRespository.findById(id).get();
4、将studentRespository.findOne(id); 改为
return studentRespository.getOne(id);
以上三种办法,第二、三种方法本人试验过可以使用,第一种本人没进行验证,如有需要可以自行验证。第四种方法进行验证因为jdk版本原因并未成功,所有推荐大家使用第二三种方法。

以上均来自个人验证。

https://blog.csdn.net/ssllkkyyaa/article/details/96967503

2.

BeanUtils.copyProperties(productInfo,productInfoVO);可以将一个对象里的属性值复制到另外一个对象中

3.@Transient

在Service层使用在变量上是可以避免该变量与数据库因对应不存在而引起的报错。

4.@JsonInclude(JsonInclude.Include.NON_NULL)

可用于在后端向前端返回Json数据时数据为null的情况下不返回那个null的数据

5.使用@Valid+BindingResult进行controller参数校验

https://www.jianshu.com/p/9e33ec934ff0

发布了22 篇原创文章 · 获赞 0 · 访问量 455

猜你喜欢

转载自blog.csdn.net/qq_36956082/article/details/104264598
今日推荐