关于 SpringMVC+Spring+MyBatis 基于注解整合(4)

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得到如下界面

关于 SpringMVC+Spring+MyBatis 基于注解整合

OK!大功告成,注意前4步里面注解的运用,后面的步骤和往常的写法无异,想必大家都很熟悉了吧。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/3d7705eee9b36ce602f85539651659ac.html