maven spring mvc jsp语法教程

引入c标签库

<dependency>
    <groupId>jstl</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>

Controller层代码

package com.qx.springmvcdemo.controller;

import com.qx.springmvcdemo.entity.DxRecord;
import com.qx.springmvcdemo.service.IRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/toHome")
public class HomeController {
    @Autowired
    private IRecordService recordService;
    @RequestMapping("/index")
    @ResponseBody
    public ModelAndView index(){
        ModelAndView mv = new ModelAndView("home/index");
        List<DxRecord> recordList = recordService.selectList();
        mv.addObject("list",recordList);
        return mv;
    }
}

jsp页面代码:

<%--
  Created by IntelliJ IDEA.
  User: qianxiao
  Date: 2022/1/19
  Time: 21:06
  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>home</title>
</head>
<body>
<h2><b>index</b></h2>
<table border=1 width="200">
<c:forEach var="item" items="${list}">
<tr>
                <td>${item.id}</td>
                <td>${item.rfrom}</td>
                <td>${item.modul}</td>
                <td>${item.type}</td>
                <td>${item.method}</td>
                <td>${item.url}</td>
                <td>${item.requestParam}</td>
                <td>${item.responseParam}</td>
                <td>${item.userId}</td>
                <td>${item.ip}</td>
                <td>${item.optionTime}</td>
                <td>${item.userAgent}</td>
                <td>${item.rdesc}</td>
            </tr>
</c:forEach>
</table>
</body>
</html>

最后效果

 

posted @ 2022-01-22 18:33  浅笑19  阅读(72)  评论(0编辑  收藏  举报