我正在使用Spring Boot,Spring Data,Thymeleaf创建一个TO-DO列表。任何人都可以告诉我,我的语法是否正确。这是我第一次使用spring boot的应用程序。我收到此错误org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "" (index)
这是index.html
<div th:if test="${mode=='MODE_HOME'}">
<div class="container" id ="homeDiv">
<div class="jumbotron text-center">
<h1>Welcome to Tasks Manager</h1>
</div>
</div>
</div>
<div th:if test="${mode=='MODE_TASKS'}">
<div class="container text-center" id ="tasksDiv">
<h3>My Tasks</h3>
<hr/>
<div class="table-responsive">
<table class="table table-striped table-bordered text-left">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Date</th>
<th>Finished</th>
</tr>
</thead>
<tbody>
<tr th:each="task: ${tasks}">
<td th:text="${task.id}"></td>
<td th:text="${task.name}"></td>
<td th:text="${task.description}"></td>
<td th:text="${task.dateCreated}"></td>
<td th:text="${task.finished}"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div th:if test="${mode=='MODE_NEW' || mode=='MODE_UPDATE'}">
<div class="container text-center">
<h3>Manage Task</h3>
<hr/>
<form class="form-horizontal" method="POST" action="save-task">
<input type="hidden" name="id" value="${task.id}"/>
<div class="form-group">
<label class="control-label col-md-3">Name</label>
<div class="col-md-7">
<input type="text" class="form-control" name="name" placeholder="name" value="${task.name}"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Description</label>
<div class="col-md-7">
<input type="text" class="form-control" name="description" placeholder="name" value="${task.description}"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Finished</label>
<div class="col-md-7">
<input type="radio" class="col-sm-1" name="finished" placeholder="finished" value="true"/>
<div class="col-sm">Yes</div>
<input type="radio" class="col-sm-1" name="finished" placeholder="finished" value="false"/>
<div class="col-sm">No</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Save"/>
</div>
</div>
</form>
</div>
</div>
这是MainController
@Controller
@RequestMapping("/")
public class MainController {
@Autowired
private TaskService taskService;
@RequestMapping(method = RequestMethod.GET)
public String home(Model model){
model.addAttribute("mode", "MODE_HOME");
return "index";
}
@RequestMapping(method = RequestMethod.GET, value = "/all-tasks")
public String allTasks(Model model){
model.addAttribute("tasks", taskService.findAll());
model.addAttribute("mode", "MODE_TASKS");
return "index";
}
@RequestMapping(method = RequestMethod.GET, value = "/new-task")
public String newTask(Model model){
//List<Task> taskList = taskService.findAll();
model.addAttribute("mode", "MODE_NEW");
return "index";
}
@RequestMapping(method = RequestMethod.GET, value = "/save-task")
@PostMapping("/save-task")
public String saveTask(@ModelAttribute Task task, Model model) {
taskService.save(task);
model.addAttribute("tasks", taskService.findAll());
model.addAttribute("mode", "MODE_TASKS");
return "index";
}
@RequestMapping(method = RequestMethod.GET, value = "/update-task")
public String updateTask(@RequestParam int id, Model model){
model.addAttribute("tasks", taskService.findTask(id));
model.addAttribute("mode", "MODE_UPDATE");
return "index";
}
@RequestMapping(method = RequestMethod.GET, value = "/delete-task")
public String deleteTask(@RequestParam (required = false) int id, Model model){
taskService.delete(id);
model.addAttribute("tasks", taskService.findAll());
model.addAttribute("mode", "MODE_TASKS");
return "index";
}
}