2
春天啓動的應用程序不會加載CSS文件形成搖籃春天啓動不加載CSS文件:請求方法「GET」不支持
進口在我的控制器我有方法,看起來像這樣
@RequestMapping(value = "/")
public String home(){
return "user/index";
}
materializecss庫
的index.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="layout/default">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initialscale= 1,
maximum-scale=1.0, user-scalable=no"/>
<title>Dodaj produkt</title>
</head>
<body>
<div class="row" layout:fragment="content">
</div>
</body>
</html>
和default.html中
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initialscale= 1,
maximum-scale=1.0, user-scalable=no"/>
<title>Witaj w Thymeleaf</title>
<link href="/webjars/materializecss/0.98.0/css/materialize.css"
type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
</head>
<body>
<nav class="nav-extended">
<div class="nav-wrapper">
<a href="/" class="brand-logo">Logo</a>
<a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a th:href="@{/products}">Produkty</a></li>
<li><a th:href="@{/categories}">Kategorie</a></li>
<li><a th:href="@{/cart}">Koszyk</a></li>
</ul>
<ul class="side-nav" id="mobile-demo">
<li><a th:href="@{/products}">Produkty</a></li>
<li><a th:href="@{/categories}">Kategorie</a></li>
<li><a th:href="@{/cart}">Koszyk</a></li>
</ul>
</div>
</nav>
<div layout:fragment="content"></div>
<script src="/webjars/jquery/2.1.4/jquery.js"></script>
<script src="/webjars/materializecss/0.98.0/js/materialize.js"></script>
<script type="text/javascript">
$(".dropdown-button").dropdown();
$(".button-collapse").sideNav();
</script>
<script type="text/javascript" layout:fragment="script"></script>
</body>
</html>
我收到提示
WARN 4520 --- [nio-8080-exec-2] o.s.web.servlet.PageNotFound : Request method 'GET' not supported
和CSS樣式未加載
我正在試圖找到解決辦法,但我找不到任何與我的問題
[編輯] 我沒有做任何事情,除了創建另一個簡單的應用程序,以確定這些webjar是否可以工作。它正在工作,所以我重新啓動主應用程序,問題幾乎消失了。現在的CSS文件加載正常,但我仍然得到警告,請求方法'GET'不支持,雖然一切看起來不錯,現在 [編輯] 仍然無法正常工作,在另一個應用程序的CSS文件加載和我的主要的應用程序我得到405,當我試圖訪問這些
我的整個MainController看起來是這樣的,有可能被映射爲「/」
@Controller
public class MainController {
private ProductServiceImpl productsService;
private CategoryService categoryService;
private CartSession cartSession;
@Autowired
public MainController(ProductServiceImpl productService, CategoryService categoryService,
CartSession cartSession){
this.productsService = productService;
this.categoryService = categoryService;
this.cartSession = cartSession;
}
@ModelAttribute
public List<CartItem> getCart(){
return cartSession.toList();
}
@RequestMapping(value = "/")
public String home(){
return "user/index";
}
@RequestMapping("products")
public String products(Model model, @PageableDefault(size = 20) Pageable pageable, SearchForm searchForm,
SortingForm sortingForm){
Page<Product> products = productsService.findAll(pageable);
PageWrapper<Product> page = new PageWrapper<>(products, "/products");
model.addAttribute("products", products);
model.addAttribute("page", page);
return "user/products";
}
@RequestMapping(value = "products", params = {"search"}, method = RequestMethod.POST)
public String searchedProducts(Model model, @PageableDefault(size = 20) Pageable pageable, SearchForm searchForm,
SortingForm sortingForm){
Page<Product> products = productsService.searchByQuery(searchForm.getToFind(), pageable);
PageWrapper<Product> page = new PageWrapper<>(products, "/products");
model.addAttribute("products", products);
model.addAttribute("page", page);
return "user/products";
}
@RequestMapping(value = "products", params = {"sort"}, method = RequestMethod.POST)
public String searchedProducts(Model model, @PageableDefault(size = 20) Pageable pageable,
SortingForm sortingForm, SearchForm searchForm){
Page<Product> products = productsService.getProductsOrdered(pageable, sortingForm.getOrderBy());
PageWrapper<Product> page = new PageWrapper<>(products, "/products");
model.addAttribute("products", products);
model.addAttribute("page", page);
return "user/products";
}
@RequestMapping("productPicture/{id}")
public void getProductPicture(HttpServletResponse response, @PathVariable("id")Long id) throws IOException {
String image = productsService.findById(id).getImagePath();
response.setHeader("Content-Type",
URLConnection.guessContentTypeFromName(image));
InputStream in = new FileSystemResource(image).getInputStream();
OutputStream out = response.getOutputStream();
IOUtils.copy(in, out);
in.close();
out.close();
}
@RequestMapping("product/{id}")
public String productInfo(@PathVariable(value = "id")Long id, Model model){
model.addAttribute("product", productsService.findById(id));
return "user/product";
}
}
你能提供你的控制器嗎? –
我已經添加了它的問題 – Dominick