Web.servlet.PageNotFound - нет сопоставления для GET - PullRequest
1 голос
/ 17 апреля 2020

Я изучаю, как работает 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>
...