gpt4 book ai didi

spring-boot - Web.servlet.PageNotFound - 没有 GET 映射

转载 作者:行者123 更新时间:2023-12-05 07:10:19 27 4
gpt4 key购买 nike

我正在学习 Spring boot + MVC 的工作原理。我可以在屏幕上显示一条消息,但我不能修改样式。 js e css 文件不与 Spring 映射。

2020-04-17 14:38:29.169  WARN 9552 --- [nio-8080-exec-3] o.s.web.servlet.PageNotFound             : No mapping for GET /js/main.js
2020-04-17 14:38:29.169 WARN 9552 --- [nio-8080-exec-2] o.s.web.servlet.PageNotFound : No mapping for GET /css/main.css
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HelloController {

@GetMapping("/")
public String index() {
return "index";
}

@PostMapping("/hello")
public String sayhello(@RequestParam("name") String name, Model model) {
model.addAttribute("name", name);
return "hello";
}

@GetMapping({"/helloworld", "/helloname"})
public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="WORLD") String name) {
model.addAttribute("name", name);
return "helloname";
}
}

我尝试修改 application.properties 中的路径,但没有任何改变。

spring.mvc.view.prefix = /WEB-INF/view/
spring.mvc.view.suffix = .jsp
spring.mvc.static-path-pattern = /resources/**

enter image description here

这是我的jsp页面。当我运行这个页面时,我收到了我之前发布的错误消息

<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<head>

<link rel="stylesheet" type="text/css"
href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" />
<c:url value="/css/main.css" var="jstlCss" />
<link href="${jstlCss}" rel="stylesheet" />

</head>
<body>
<div class="container">
<header>
<h1>Spring MVC + JSP + JPA + Spring Boot 2</h1>
</header>
<div class="starter-template">
<h1>Users List</h1>
<table
class="table table-striped table-hover table-condensed table-bordered">
<tr>
<th>Date</th>
<th>Device</th>
<!-- <th>Amount</th>
<th>OEE</th> -->
</tr>
<c:forEach items="${OEE}" var="oee">
<tr>
<!-- <td>${oee.oeeID.date}</td>
<td>${oee.oeeID.device}</td> -->
<td>${oee.amount}</td>
<td>${oee.oee}</td>
</tr>
</c:forEach>
</table>
</div>

</div>

<script type="text/javascript"
src="webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>

</html>

最佳答案

用这个

@Configuration
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
}

关于spring-boot - Web.servlet.PageNotFound - 没有 GET 映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61272328/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com