我有一个spring-boot-thymeleaf应用程序,我在其中进行requestmapping调用
如果你看一下图片load-products.jpg,我得到了正确的列表,但只有在我第一次启动调用时才会出现这种情况http://localhost:8080/services/searchbydepartment?department=制冰机
我有链接如果你向下滚动你会看到链接
全制冷制冰机。。。。。。。
如果我第二次点击任何链接调用这个url
http://localhost:8080/searchbydepartment?department=制冰机
会产生错误请参见附件
因此,如果我回到我的thymeleaf页面并将服务附加到我所有的th:href,比如th:href=“@{services/searchbydepartment}
然后我得到了一个双重服务,在我的呼吁,这是创造另一个错误
这是其他电话正在创建的http://localhost:8080/services/services/searchbydepartment?department=制冷http://localhost:8080/services/services/searchbydepartment?department=食品准备
您可以看到单词services出现了两次,这造成了一个no explicit mapping错误,因为它找不到urlMap
我尝试了一切重定向,删除字服务从控制器添加到thymeleaf和它不工作。。怎么回事。。代码在我看来是这样的
th:href=“@{services/searchbydepartment(department='icemachines')}
控制器将@requestmapping(value=“/services”)作为注解,或将其添加到方法调用中,如@requestmapping({“services/searchbydepartment”})
目录结构对我来说似乎很好,但这段代码不起作用
<div class="prod-list">
<a th:href="@{services/allList}" th:classappend="${activeAll}? 'active'"
class="list-group-item">All</a>
<a class="categories list-group-item ice" th:href="@{services/searchByDepartment(department='iceMachines')}"
th:classappend="${activeIceMachines} ? 'active'">Ice Machine</a>
<a class="categories list-group-item refrigeration" th:href="@{services/searchByDepartment(department='refrigeration')}"
th:classappend="${activeRefrigeration} ? 'active'">Refrigeration</a>
<a class="categories list-group-item cook" th:href="@{services/searchByDepartment(department='cookingEquipment')}"
th:classappend="${activeCooking} ? 'active'">Cooking Equipment</a>
<a class="categories list-group-item cook" th:href="@{services/searchByDepartment(department='foodPreparation')}"
th:classappend="${activeCooking} ? 'active'">Food Preparation</a>
<a class="categories list-group-item bar" th:href="@{services/searchByDepartment(department='barEquipment')}"
th:classappend="${activeBar} ? 'active'">Bar Equipment</a>
</div>
@Controller
@AllArgsConstructor
@RequestMapping(value = "/services")
public class ProductController {
private final ServiceClientService serviceClientService;
private final ProductService productService;
@RequestMapping({"", "/", "/allList","/allList"})
public String productList(Model model) {
List<Product> productList = productService.findAll();
model.addAttribute("productList", productList);
return "services/allList";
}
@RequestMapping({"/searchByDepartment"})
public String searchByDepartment(@RequestParam("department") String department, Model model, Principal principal) {
model.addAttribute("user", locateUser(principal));
String classActiveDepartment = "active" + department;
classActiveDepartment = classActiveDepartment.replaceAll("\\s+", "");
classActiveDepartment = classActiveDepartment.replaceAll("&", "");
System.out.println(classActiveDepartment + "+++++++++++xyz");
model.addAttribute(classActiveDepartment, true);
List<Product> productList = productService.findByDepartment(department);
if (productList.isEmpty()) {
model.addAttribute("emptyList", true);
return "services/allList";
}
model.addAttribute("productList", productList);
return "services/allList";
}
暂无答案!
目前还没有任何答案,快来回答吧!