【发布时间】:2018-01-18 07:35:34
【问题描述】:
我使用 Spring Boot 开发了一个简单的网页,我使用类和方法级别请求映射注释的组合,但它在以下场景下不起作用。
当我点击http://localhost:9999/products 时工作 当我点击http://localhost:9999/home/products时不工作
控制器类: 包 com.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(value= {"/","/home/"})
public class MainController {
@RequestMapping(value = {"products"},method=RequestMethod.GET)
public String index()
{
return "Home.html";
}
}
【问题讨论】:
-
您收到的错误是什么?将日志级别设置为调试并检查 URL 映射,您应该会看到一行确认您的 URL 到 index() 函数的映射。
-
你能分享你的 application.properties 和 View Resolver 映射吗..
-
错误我收到 Whitelabel 错误页面 此应用程序没有 /error 的显式映射,因此您将其视为后备。出现意外错误(类型=未找到,状态=404)。没有可用的消息
-
Application.properties 文件只有一个条目,即 server.port=9999
标签: spring-boot controller request-mapping