有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

SpringMVC在Java中通过jsp显示列表的问题

嗨,我的项目有问题,那是我的帖子。jsp

<!DOCTYPE html>
<html>
<head>
<title>Blog Site-posts</title>
</head>
<body>
 <div class="container">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Description</th>
                <th>Date</th>
                <th>Completed</th>
                <th>Written by</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${posts}" var="Post">
                <tr>
                    <td>${Post.postId}</td>
                    <td><fmt:formatDate pattern="dd/MM/yyyy"
                            value="${post.postDate}" /></td>
                    <td>${Post.text}</td>
                    <td>${Post.authorId}</td>
                </tr>
            </c:forEach>
        </tbody>
    </table>
</div>
</body>
</html>

那是我的邮政控制器

@Controller
public class PostController {

    @Autowired
    PostService postService;

    @RequestMapping(value="/posts",method = RequestMethod.GET)
    public String showPosts(ModelMap model) {
        model.addAttribute("posts",postService.findall());
        return "posts";
    }
}

这是我的博士后课程

public class Post {

@Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int postId;

    //@Column(unique=true)
    //@NotEmpty
    private String title;
    //@Column(length=20000)
    @Size(max=20000, message="Message cannot be longer than 20000 characters!")
    //@NotEmpty
    private String text;
    private Date postDate;
    private int authorId;

我想在jsp中显示带有帖子的列表元素,看看它是如何工作的,但看起来是这样的:

enter image description here

jsp或控制器有什么问题


共 (1) 个答案

  1. # 1 楼答案

    将此项添加到标记html之前的posts.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>