请求http://localhost:8080/restful/person?id=1提示请求资源[/restful/restful/person]不可用
问题描述:
在json序列化章节增加findByPersonId中无法通过请求http://localhost:8080/restful/person?id=1获取返回值。提示请求资源[/restful/restful/person]不可用。
相关截图:
报错信息

tomcat设置

相关代码:
//RestfulController.java
package com.imooc.restful.controller;
import com.imooc.restful.entity.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/restful")
public class RestfulController {
@GetMapping("/request")
// @ResponseBody
public String doGetRequest() {
return "{\"message\": \"getting...\"}";
}
@PostMapping("/request")
// @ResponseBody
public String doPostRequest(){
return "{\"message\": \"inserting...\"}";
}
@PutMapping("/request")
// @ResponseBody
public String doPutRequest(){
return "{\"message\": \"updating...\"}";
}
@DeleteMapping("/request")
// @ResponseBody
public String doDeleteRequest(){
return "{\"message\": \"deleting...\"}";
}
@GetMapping("/person")
public Person findByPersonId(Integer id){
Person person = new Person();
if(id == 1){
person.setName("person1");
person.setAge(20);
}
else if(id == 2){
person.setName("person2");
person.setAge(22);
}
return person;
}
}7
收起
正在回答
1回答
同学你好,根据浏览器报错路径显示,有两个restful

同学可以检查下idea的如下位置是否是/restful,如果是,建议同学改成/试试,如下

祝学习愉快~
java工程师2020版
- 参与学习 人
- 提交作业 9410 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星