[英]static css not loading for spring boot project
the problem: as u can see from the image, the browser is unable to load the css files. 问题:从图像中可以看到,浏览器无法加载css文件。 I also get this exception in STS console: 我在STS控制台中也遇到了此异常:
[2m2018-02-10 19:00:57.770[0;39m [33m WARN[0;39m [35m16292[0;39m [2m---[0;39m [2m[nio-8080-exec-3][0;39m [36m.wsmsDefaultHandlerExceptionResolver[0;39m [2m:[0;39m Resolved exception caused by Handler execution: org.springframework.web.bind.UnsatisfiedServletRequestParameterException: Parameter conditions "cancel" not met for actual request parameters: [2m2018-02-10 19:00:57.770 [0; 39m [33m WARN [0; 39m [35m16292 [0; 39m [2m --- [0; 39m [2m [nio-8080-exec-3] [0 ; 39m [36m.wsmsDefaultHandlerExceptionResolver [0; 39m [2m:[0; 39m]由处理程序执行引起的已解决异常:org.springframework.web.bind.UnsatisfiedServletRequestParameterException:实际请求参数未满足“取消”参数条件:
the code was working fine until I completed the included Controller
any one has an idea why this is happening? 有人知道为什么会这样吗? Error from the browser(firefox) 来自浏览器的错误(Firefox)
][1]
!DOCTYPE html> !DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en" th:fragment="head">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- jQuery library -->
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7 /js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link th:href="@{/css/style2.css}" rel="stylesheet" media="screen" />
<link th:href="@{/css/login.css}" rel="stylesheet" media="screen"/>
<link rel="stylesheet" type="text/css" media="screen" th:href="@{/css/login.css}"/>
</head>
<body>
</body>
</html>
Controller 控制者
package com.intelbs.controllers;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.intelbs.dao.Customer;
import com.intelbs.dao.Employee;
import com.intelbs.dao.Expense;
import com.intelbs.dao.Note;
import com.intelbs.services.ExpenseService;
@Controller
public class ExpenseController {
@Autowired
private ExpenseService expService;
@RequestMapping(value = "/monthlyExpenses", method = RequestMethod.GET)
public String listMonthlyExpenses(Model model, String month, String year) {
model.addAttribute("monthlyExpenses", expService.monthExpense(month, year));
return "monthlyexpensesform";
}
@RequestMapping(value="new_expense", method = RequestMethod.GET)
public String diplayAddExpenseForm( Model model) {
System.out.println("inside display");
model.addAttribute("expense", new Expense());
return "addexpenseform";
}
@RequestMapping(params= "save", method= RequestMethod.POST)
public String processAddExpenseForm(@Valid Expense expense, BindingResult br,
Model model, RedirectAttributes ra) {
System.out.println("inside processform");
if(br.hasErrors()) {
System.out.println("inside has er");
return"addexpenseform";
}
model.addAttribute("expense", expense);
expService.saveExpense(expense);
ra.addFlashAttribute("expense", expense);
return "redirect:/customers";
}
@RequestMapping(params = "cancel",method= {RequestMethod.GET, RequestMethod.POST})
public String cancelAddExpenseForm() {
return "redirect:/customers";
}
}
[Browser error]: https://i.stack.imgur.com/xO4l5.png
I think you are incorrectly using param
instead of value
in @RequestMapping
. 我认为您错误地使用了param
而不是@RequestMapping
的value
。
Actually param
is used to narrow down the requests that are matched for a URL 实际上, param
用于缩小与URL匹配的请求的范围
A sequence of "myParam=myValue" style expressions, with a request only mapped if each such parameter is found to have the given value. 一系列“ myParam = myValue”样式表达式,仅当发现每个这样的参数具有给定值时,才会映射请求。
Refractor your code like this. 像这样折断您的代码。
@RequestMapping(value="/new_expense", method = RequestMethod.GET)
public String diplayAddExpenseForm( Model model) {
System.out.println("inside display");
model.addAttribute("expense", new Expense());
return "addexpenseform";
}
@RequestMapping(value= "/save", method= RequestMethod.POST)
public String processAddExpenseForm(@Valid Expense expense, BindingResult br,
Model model, RedirectAttributes ra) {
System.out.println("inside processform");
if(br.hasErrors()) {
System.out.println("inside has er");
return"addexpenseform";
}
model.addAttribute("expense", expense);
expService.saveExpense(expense);
ra.addFlashAttribute("expense", expense);
return "redirect:/customers";
}
@RequestMapping(value= "/cancel",method= {RequestMethod.GET, RequestMethod.POST})
public String cancelAddExpenseForm() {
return "redirect:/customers";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.