我正在尝试在Springboot中使用搜索引擎列出一个简单的列表,但无法执行报告列表。当我尝试获取视图报告中的信息时,我没有得到对象的信息。
如果我尝试在控制器中使用
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="370dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:layout_margin="4dp"
app:cardBackgroundColor="#DDE1E2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<FrameLayout
android:id="@+id/total_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardElevation="30dp">
<View
android:id="@+id/view"
android:layout_width="100dp"
android:layout_height="5dp"
android:background="#272727" />
</androidx.cardview.widget.CardView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:backgroundTint="@android:color/white"
app:borderWidth="0dp"
app:elevation="10dp"
app:fabSize="mini" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center"
android:layout_marginTop="30dp"
android:text="INDIA"
android:textSize="30sp"
android:textStyle="bold" />
</FrameLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
org.thymeleaf.exceptions.TemplateInputException:模板解析期间发生错误(模板:“类路径资源[templates / views / listReport.html]”)
如果我在控制器中使用
model.addAttribute("reports", reportService.findAll();
我什么也没收到。
视图:
model.addAttribute("reports", reportService.findByTitle(title));
控制器:
<div layout:fragment="content" class="container sandstone">
<form action="/report" class="form-inline">
<div class="form-group mb-2">
<input type="text" class="form-control" name="name" placeholder="Search Title" />
<input type="submit" value="Search" class="btn btn-primary"/>
</div>
</form>
<div class="card">
<div class="card card-body">
<table class="table table-hover">
<thead>
<tr>
<th>Date</th>
<th>Title</th>
<th>Link</th>
<th>Description</th>
<th>Add</th>
</tr>
</thead>
<tbody>
<tr th:each="report:${reports}">
<td th:text="${report.date}"></td>
<td th:text="${report.title}"></td>
<td th:text="${report.link}"></td>
<td th:text="${report.description}"></td>
<td><a th:href="@{/addReport()}" class="btn btn-dark">AddReport</a></td>
</tr>
</tbody>
</table>
</div>
</div>
}
服务:
@Controller
public class ReportController {
@Autowired
ReportService reportService;
@GetMapping("/report")
public String listReports(Model model, @RequestParam(defaultValue="") String title) {
model.addAttribute("report", reportService.findByTitle(title));
return "views/listReport";
}
@GetMapping("/addReport")
public String reportForm(Model model) {
model.addAttribute("report", new Report());
return "views/reportForm";
}
}
存储库:
@Service
public class ReportService {
@Autowired
private ReportRepository reportRepository;
public void createReport(Report report) {
report.setTitle(report.getTitle());
report.setDate(report.getDate());
report.setDescription(report.getDescription());
report.setLink(report.getLink());
reportRepository.save(report);
}
public Report findOne(Long id) {
return reportRepository.findOne(id);
}
public List<Report> findAll() {
return reportRepository.findAll();
}
public List<Report> findByTitle(String title) {
return reportRepository.findByTitleLike("%"+title+"%");
}
答案 0 :(得分:0)
多亏了Ayrtonn,我的问题才得以解决 Thymeleaf无法解析表达式
@{/addReport()