[英]Whitelabel Error Page - Error in Spring Boot Application
我在运行 Spring 引导应用程序时收到“Whitelabel 错误页面”,即使在映射 URL 之后也是如此。
我已经提到了我的 application.properties 文件和一个 controller 文件
application.properties file
server.port=8087
server.servlet.context-path=/starts
spring.h2.console.enabled=true
---------------------------------------------
TestController.java file
package com.example.firstproject.Controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.firstproject.Entity.Employee;
import com.example.firstproject.Service.EmployeeService;
@RestController
public class TestController {
@Autowired
EmployeeService empService;
@RequestMapping("/save")
public int test(@RequestBody Employee emp) {
return empService.saveEmployee(emp);
//return 0;
}
@RequestMapping("/getAll")
public List<Employee> home() {
return empService.getAll();
}
@RequestMapping("/test")
public String test()
{
return "success";
}
}
我还附上了运行项目Whitelabel Error Page时遇到的错误图像
我应该如何消除这个错误?
您的 /save 映射是一个 POST 请求,需要一个 Employee object。 您不能从浏览器 URL 调用它。 浏览器调用只是 GET 请求。 您应该使用 Postman 之类的工具来发送 POST 请求。
您需要提及您正在执行的 RequestMapping 类型@RequestMapping(value = "/save", method = RequestMethod.POST)
或PostMapping("/save")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.