详解Spring MVC 构建入门级 Web 应用程序( 三 )


}
EmployeeManagerImpl.java<pre>import java.util.List;</pre>import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import com.howtodoinjava.demo.dao.EmployeeDAO;import com.howtodoinjava.demo.model.EmployeeVO;@Servicepublic class EmployeeManagerImpl implements EmployeeManager { @Autowired EmployeeDAO dao; public List<EmployeeVO> getAllEmployees() { return dao.getAllEmployees(); }}employeesListDisplay.jsp这个jsp被用于显示系统中的所有员工 。它循环遍历employee集合,并且在一个表中打印他们的详细信息 。这符合MVC模式的视图层 。
<pre><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%></pre><html><head><title>Spring MVC Hello World</title></head><body><h2>All Employees in System</h2><table border="1"><tr><th>Employee Id</th><th>First Name</th><th>Last Name</th></tr><c:forEach items="${employees}" var="employee"><tr><td>${employee.id}</td><td>${employee.firstName}</td><td>${employee.lastName}</td></tr></c:forEach></table></body></html>现在在您的应用程序服务器(我用的是Tomcat 7)部署应用程序 。并点击“http://localhost:8080/springmvcexample/employee-module/getAllEmployees” 。如果你已正确配置所有内容,你将会在屏幕下看到:

详解Spring MVC 构建入门级 Web 应用程序

文章插图
 




推荐阅读