我有一个带有bootstrap的Java,Spring,thymeleaf webapplication。
我的控制器:
@Controller
@RequestMapping("/productmerger")
public class SetupController {
@Autowired
private TradingModel tradingModel;
@RequestMapping(value = "start", method = RequestMethod.GET)
//@ResponseBody //can be deleted due to thymeleaf
public String start(ModelMap modelMap) {
modelMap.put("productList", tradingModel.getAvailableProducts());
return "start";
}
@RequestMapping(value = "start", method = RequestMethod.POST)
public String startPost(@RequestParam("Products") String[] products, HttpEntity<String> httpEntity) {
tradingModel.getContentList().clear();
for (String product : products) {
tradingModel.getContentList().add(new Product(product));
}
return "redirect:/handleDetails";
}
}
我的HTML
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:replace="template :: head">
</head>
<body>
<div class="container">
<form method="post" action="start.html">
<h2>Chose what you want to trade</h2>
<label>
<select th:name="Products" class="selectpicker" multiple="multiple">
<!--/*@thymesVar id="productList" type="java.util.List"*/-->
<option th:each="product : ${productList}"><a th:text="${product}"></a></option>
</select>
</label>
<button th:type="submit" class="btn btn-info">Send</button>
</form>
</div>
<div th:replace="template :: footer"></div>
</body>
</html>
来自浏览器的源代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title></title>
<link rel="stylesheet" href="webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" />
<link rel="stylesheet" href="webjars/bootstrap/3.3.7-1/css/bootstrap-theme.min.css" />
<link rel="stylesheet" href="webjars/bootstrap-select/1.12.0/css/bootstrap-select.min.css" />
</head>
<body>
<div class="container">
<form method="post" action="start.html">
<h2>Chose what you want to trade</h2>
<label>
<select class="selectpicker" multiple="multiple" name="Products">
<option><a>Table</a></option>
<option><a>Glas</a></option>
<option><a>Fork</a></option>
</select>
</label>
<button class="btn btn-info" type="submit">Send</button>
</form>
</div>
<footer>
<script src="webjars/jquery/3.2.0/jquery.min.js"></script>
<script src="webjars/bootstrap/3.3.7-1/js/bootstrap.min.js"></script>
<script src="webjars/bootstrap-select/1.12.0/js/bootstrap-select.js"></script>
</footer>
</body>
</html>
我的template.html的一部分
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:fragment="head">
<meta charset="UTF-8"/>
<!--/*@thymesVar id="title" type="String"*/-->
<title th:text="${title}">Hello</title>
<link th:href="@{webjars/bootstrap/3.3.7-1/css/bootstrap.min.css}" rel="stylesheet"/>
<link th:href="@{webjars/bootstrap/3.3.7-1/css/bootstrap-theme.min.css}" rel="stylesheet"/>
<link th:href="@{webjars/bootstrap-select/1.12.0/css/bootstrap-select.min.css}" rel="stylesheet"/>
</head>
start.html的路径
d:\程序\收存箱\ HelloSpring3 \ SRC \主\资源\模板\的start.html
css的路径
C:!\用户\ N-二rG.m2 \库\有机\ webjars \自举\ 3.3.7-1 \自举-3.3.7-1.jar \ META-INF \资源\ webjars \引导\ 3.3 .7-1 \ CSS \ bootstrap.min.css
我的问题:
在浏览器中正确显示的链接后面:
<link rel="stylesheet" href="webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" />
实际上是错误的,因为只要我将鼠标悬停在它上面或点击它,它就会将我重定向到
http://localhost:8080/productmerger/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css
所以/ productmerger / part在这里是错的。我怎么能摆脱它?
请帮帮我。
非常感谢!
答案 0 :(得分:0)
首先添加/
,您可能需要与上下文相关的网址:
<link th:href="@{/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css}" rel="stylesheet"/>
有关详细信息,请参阅Thymeleaf Standard URL Syntax。