【发布时间】:2020-04-09 10:13:42
【问题描述】:
我刚开始在 MVC 中开发一个 spring-boot 应用程序 (Java)。在控制器类中,
@GetMapping("/{id}/age")
public ResponseEntity<Integer> getStudentAge(@PathVariable Long id) {
Integer age = studentService.retrieveAgeById(id);
return new ResponseEntity<Integer>(age, HttpStatus.OK);
}
用一个简单的SQL数据,就这么简单:
INSERT INTO student (id, name, age, gender) VALUES (1, 'Rio', 5, 'Male');
当我运行应用程序并检查带有路径的网页时:http://localhost:8080/1/age
我收到未打印年龄的回复:
Result
存储库包中使用的查询是:
@Query("select d.id, d.age from Student d where d.id=:id")
Integer findAgeById(Long id);
另外,学生姓名、性别(Type:String)的请求也成功了。但是,年龄请求(类型:整数)没有产生类似的结果。
【问题讨论】:
标签: java sql spring-boot rest spring-mvc