【发布时间】:2023-03-12 14:41:01
【问题描述】:
我目前正在思考为什么包含参数@RequestBody Car car 会破坏我的终点。
我对 Spring boot 非常陌生,并试图将 json 字符串发布到我的休息控制器。
这是我的控制器:
@RestController
@RequestMapping("/v1/car")
@EnableWebMvc
public class CarController {
private static final Log LOGGER = LogFactory.getLog(CarController.class);
@Autowired
private CarService carService;
@RequestMapping(value="/{accountId}", method = RequestMethod.POST, consumes={"text/plain", "application/*"})
ResponseEntity<?> start(@PathVariable final Integer accountId, @RequestBody Car car) {
System.out.println("E: "+accountId);
final long tid = Thread.currentThread().getId();
final Boolean status = this.smarterWorkFlowService.startWorkFlow(accountId, car);
return new ResponseEntity<Car>(new Car(), HttpStatus.ACCEPTED);
}
}
我也使用 jackson 作为我的 json 解析器。我找了好几个小时,但没有发现任何东西可以帮助我解释为什么我收到了 415 回复。
{
"timestamp": 1425341476013,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Unsupported Media Type",
"path": "/v1/experiences/12"
}
感谢您的帮助!!
【问题讨论】:
标签: json spring spring-mvc jackson spring-boot