import com.bdqn.lyrk.ssm.study.entity.StudentEntity;
import com.bdqn.lyrk.ssm.study.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@Controller
public class IndexController {
@Autowired
private IStudentService studentService;
@GetMapping("/index")
public String index(ModelMap modelMap) {
List<StudentEntity> list = studentService.selectAll();
modelMap.put("students", list);
return "index";
}
}
9.index.jsp文件中内容
<%--
Created by IntelliJ IDEA.
User: chen.nie
Date: 2017/12/23
Time: 下午8:40
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<c:forEach items="${students}" var="student">
${student.stuName}
</c:forEach>
</body>
</html>
10.启动tomcat后访问:8080/portal/index得到如下界面
OK!大功告成,注意前4步里面注解的运用,后面的步骤和往常的写法无异,想必大家都很熟悉了吧。