Я пробую простой список с поисковой системой в Springboot, и я не могу сделать список отчетов.Когда я пытаюсь получить информацию в отчете вида, я не получаю информацию об объекте.
, если я пытаюсь использовать в контроллере
model.addAttribute("reports", reportService.findAll();
org.thymeleaf.exceptions.TemplateInputException: ошибка произошла во время синтаксического анализа шаблона (template: "ресурс пути к классу [templates / views / listReport.html]")
, и если я использую в контроллере
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+"%");
}
}
хранилище:
public interface ReportRepository extends JpaRepository<Report, Long>{
List<Report> findByTitleLike(String string);