这是springboot的一个控制器,我想写一个重定向到html页面的函数,但它总是以404响应,下面是代码和属性。‘
@Component
@Controller
@RequestMapping("/Weixin")
public class KindlePocketController {
private static final long serialVersionUID = 1L;
@Autowired
private TextBookInfoSearchService searchService;
@RequestMapping("/homepage")
public String toIndex() {
System.out.println("redirecting to homepage...");
return "index";
}
}‘application.properties’
spring.view.prefix=/WEB-INF/views/
spring.view.suffix=.html‘
程序可以进入函数,输出是ok的。index.html位于以下路径:/WEB-INF/views/index.html。还有没有其他配置?非常感谢
发布于 2016-05-15 16:57:45
您的配置不正确,请尝试以下操作:
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.html它是spring.mvc.view.*,而不是spring.view.*。
PS:使用STS或InteliJ提供的智能感知。
发布于 2019-09-06 04:23:29
此映射@RequestMapping("/Weixin")映射到名为: Example: localhost:8080/Weixin的URL
其次,您有另一个映射@RequestMapping("/homepage"),它映射到URL: Example2: localhost:8080/Weixin/homepage
每当您尝试访问Example2网址时,您都会被重定向到索引页
https://stackoverflow.com/questions/37234033
复制相似问题