我是 Spring Boot 的新手,并嘗試使用 Spring Boot 和 JSP 創建一個簡單的 ToDo 應用程式。我試圖在我的 JSP 中顯示待辦事項串列,但它沒有反映。我嘗試了所有方法,而在 IntelliJ 想法中放置斷點時,我能夠在我的 repo 中看到待辦事項串列。
ToDoView.jsp
<%@ include file="header.jsp"%>
<%@ include file="navigation.jsp"%>
<div class="container">
<div>
<a type="button" class="btn btn-primary btn-md" href="/add-todo">Add Todo</a>
</div>
<br>
<div class="panel panel-primary">
<div class="panel-heading">
<h3>List of TODO's</h3>
</div>
<div >
<table >
<thead>
<tr>
<th width="40%">Description</th>
<th width="40%">Target Date</th>
<th width="20%"></th>
</tr>
</thead>
<tbody>
${todolist}
<c:forEach items="${todolist}" var="todo">
<tr>
<td>${todo.description}</td>
<td>${todo.getDescription()}</td> <td><fmt:formatDate value=${todo.getToDoDate()} pattern="dd/MM/yyyy" /></td>
<td><a type="button" href="/update-todo?id=${todo.getId()}">Update</a>
<a type="button" href="/delete-todo?id=${todo.getId()}">Delete</a></td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
<%@ include file="footer.jsp"%>
HomeController.java
package com.toDoApp.ToDoApp;
@Controller
public class HomeController
{
@Autowired
ToDoRepo repo;
@RequestMapping("/")
public static String home()
{
return "Home";
}
@GetMapping(path = "/list-todos", produces = {"application/json"})
public String toDoView(Model m)
{
m.addAttribute("todolist", repo.findAll());
return "ToDoView";
}
}
ToDoRepo.java
public interface ToDoRepo extends JpaRepository<ToDoList, Integer>
{
}
ToDoList.java
package com.toDoApp.ToDoApp;
import javax.persistence.*;
import java.util.Date;
@Entity
public class ToDoList
{
@Id
private int id;
private String description;
private Date toDoDate;
public ToDoList()
{
super();
}
public ToDoList(String description, Date toDoDate)
{
super();
this.description = description;
this.toDoDate = toDoDate;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getToDoDate() {
return toDoDate;
}
public void setToDoDate(Date toDoDate) {
this.toDoDate = toDoDate;
}
}
我嘗試了所有其他方法,但找不到任何東西。請幫幫我。
謝謝你
uj5u.com熱心網友回復:
添加jasper依賴
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
并像這樣更改 td 標簽
${todo.getDescription()}uj5u.com熱心網友回復:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
嘗試添加 jasper 依賴項
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/515173.html
