gpt4 book ai didi

java - Spring MVC 表

转载 作者:行者123 更新时间:2023-12-02 03:55:49 24 4
gpt4 key购买 nike

我试图在 Spring MVC 中的表中显示数据,我已经粘贴了下面的 JSP 代码和 Controller 代码,当我点击 url/test/grid 时,我可以看到它点击了 Employee.jsp 页面,但没有加载任何内容。 Chrome 控制台不会显示任何错误,也不会调用 getActiveTeamData 方法。

JSP代码

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Employee</title>
<body>
<c:if test="${!empty employees}">
<table align="center" border="1">
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Start Date</th>
</tr>

<c:forEach items="${employees}" var="category">
<tr>
<td><c:out value="${employee.name}"/></td>
<td><c:out value="${employee.position}"/></td>
<td><c:out value="${employee.salary}"/></td>
<td><c:out value="${employee.office}"/></td>
<td><c:out value="${employee.start_Date}"/></td>
</tr>
</c:forEach>
</table>
</c:if>
</body>
</html>

Java代码

@Controller
@RequestMapping(value = "/test")
public class EmployeeController {

private static final Logger logger = Logger.getLogger(EmployeeController.class);

@RequestMapping(value = "/grid", method = RequestMethod.GET)
public String tableServiceCall() {

logger.info("Log4j info is working");
logger.warn("Log4j warn is working");
logger.debug("Log4j debug is working");
logger.error("Log4j error is working");
System.out.println("System out is working");
return "Employee";
}



@RequestMapping(value = "/employees", method = RequestMethod.GET)
@ResponseBody
public List<EmployeeDTO> getActiveTeamData(@PathVariable String name) {

List<EmployeeDTO> listEmployees = new ArrayList<EmployeeDTO>();
for (int i = 0; i < 4; i++) {
EmployeeDTO employeeDTO1 = new EmployeeDTO();

employeeDTO1.setName("Java Honk");
employeeDTO1.setPosition("Architect");
employeeDTO1.setSalary("$000,800");
employeeDTO1.setOffice("NY");
employeeDTO1.setStart_Date("05/05/2010");



EmployeeDTO employeeDTO2 = new EmployeeDTO();

employeeDTO2.setName("Igor Vornovitsky");
employeeDTO2.setPosition("Sr. Architect");
employeeDTO2.setSalary("$400,800");
employeeDTO2.setOffice("NY");
employeeDTO2.setStart_Date("05/05/2011");



EmployeeDTO employeeDTO3 = new EmployeeDTO();

employeeDTO3.setName("Ramesh Arrepu");
employeeDTO3.setPosition("Architect");
employeeDTO3.setSalary("$300,400");
employeeDTO3.setOffice("NY");
employeeDTO3.setStart_Date("05/05/2009");

listEmployees.add(employeeDTO1);
listEmployees.add(employeeDTO2);
listEmployees.add(employeeDTO3);

}

return listEmployees;
}


@RequestMapping(value = "/test", method = RequestMethod.GET)
@ResponseBody
public String testApp() {
return UUID.randomUUID().toString();
}

最佳答案

tableServiceCall 不会填充 JSP View 所需的模型,因此不会显示任何内容。

@RequestMapping(value = "/grid", method = RequestMethod.GET)
public String tableServiceCall(Model model) {

List<EmployeeDTO> listEmployees = ...
// populate employee list
model.addAttribute("category", listEmployees);

return "Employee";
}

关于java - Spring MVC 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35468368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com