我无法将来自两个存储库的数据正确地注入到一个 jsp 表单中。在 index.jsp 中,我只有 "<% response.sendRedirect("category/list");%>" 当我将重定向与 /category/list 一起使用时,它会显示来自 Category 表的记录,并且还应该有来自 User 类别的记录是空格。
谢谢你的帮助
类别控制器:
@Controller
@RequestMapping("/category")
public class CategoryController {
@Autowired
private CategoryService categoryService;
@GetMapping("/list")
public String categoriesList(Model theModel){
List<Category> allCategoriesFromDatabase = categoryService.getAllCategories();
theModel.addAttribute("allCategoriesList" , allCategoriesFromDatabase);
return "test-main-page";
}
}
调度程序-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Add support for component scanning -->
<context:component-scan base-package="com.mybudget" />
<!-- Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
慕哥6287543
相关分类