Springboot,SpringCloud中常见报错解决 和 注解区别

springboot中的 一些注解区别

.@Controller和@RestController注解区别
1. @RestController注解,相当于 @Controller+@ResponseBody两个注解的结合。
@Controller类中的方法可以直接通过返回String跳转到jsp、ftl、html等模版页面。在方法上加@ResponseBody注解,也可以返回实体对象。
2. @RestController类中的所有方法只能返回String、Object、Json等实体对象,不能跳转到模版页面。
@RestController中的方法如果想跳转页面,则用ModelAndView进行封装。

二…@RequestParam和@PathVariable,@RequestBody区别

  1. @RequestParam适用于@RequestMapping(“/hi?name=?”)
  2. @PathVariable适用于@RequestMapping(“/hi/{id = 2}”)
  3. @RequestBody适用于对象
  4. 总结一下,RequestParam接收的参数是来自requestHeader中,即请求头,通常用于get请求。RequestBody注解接收的参数是来自requestBody中的,即请求体;一般用于处理非Content-Type:application/x-www-form-urlencoded编码格式的数据,比如application/json、application/xml等类型的数据;

springboot/cloud中的一些报错

一.
报错:

org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘GET’ not supported,405

解决:把postmapping,deletemapping改成Requestmapping

.
常见报错:
报错:error create bean xxxxxxxx 这种很有可能是你的pom.xml里面的依赖版本不适配导致冲突,某些注解不能正常生效。

三.
springcloud-config报错(使用config-client去访问config-server配置好的gitee的配置文件)

报错:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'foo' in value "${foo}"
	

在这里插入图片描述

解决:pom.xml里面加入了错误的依赖,应该只有starter-config,删掉第一个config-server。

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

改动之后:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

四.
报错:java.lang.IllegalArgumentException: Body parameter 0 was null
解决:
SpringMVC方法中的@requestbody注解接收数据时,当参数为null时就报这个错""
1.(@RequestBody(required=false)
2.传参数时限制authSession不能为空

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值