#spring #spring-boot
#весна #весенняя загрузка
Вопрос:
я создаю crud-проект в spring boot. у меня возникает эта проблема каждый раз, когда я не знаю, как решить то, что я пробовал до сих пор, я прикрепил работу ниже, проверьте мою работу. полный код, который я прикрепил в ссылке github здесь https://github.com/raguram1986/StudCrud
Контроллер
@Контроллер
public class StudentController {
@Autowired
private StudentService service;
@GetMapping("/")
public String viewHomePage(Model model) {
List<Student> liststudent = service.listAll();
model.addAttribute("liststudent", liststudent);
System.out.print("Get / ");
return "index";
}
@GetMapping("/new")
public String add(Model model) {
model.addAttribute("student", new Student());
return "new";
}
index.html
<tr>
<div align = "left" >
<h3><a th:href="@{'/new'}">Add new</a></h3>
</div>
</tr>
<tr>
<div class="col-sm-5" align = "center">
<div class="panel-body" align = "center" >
<table class="table">
<thead class="thead-dark">
<tr>
<th>Student ID</th>
<th>Student Name</th>
<th>Course</th>
<th>Fee</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr th:each="student : ${liststudent }">
<td th:text="${student.id}">Student ID</td>
<td th:text="${student.studentname}">StudentName</td>
<td th:text="${student.course}">Course</td>
<td th:text="${student.fee}">Fee</td>
<td>
<a th:href="@{'/edit/' ${student.id}}">Edit</a>
</td>
<td>
<a th:href="@{'/delete/' ${student.id}}">Delete</a>
</td>
</tr>
</tbody>
я получил ошибку полной ошибки, которую я прикрепил ниже кода
2020-09-21 16:34:43.091 INFO 18984 --- [ main] c.e.StudentCrud.StudentCrudApplication : Starting StudentCrudApplication on kobinath-pc with PID 18984 (C:Userskobinatheclipse-workspace1sStudentCrud.zip_expandedStudentCrudtargetclasses started by kobinath in C:Userskobinatheclipse-workspace1sStudentCrud.zip_expandedStudentCrud)
2020-09-21 16:34:43.095 INFO 18984 --- [ main] c.e.StudentCrud.StudentCrudApplication : No active profile set, falling back to default profiles: default
2020-09-21 16:34:43.977 INFO 18984 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-09-21 16:34:44.072 INFO 18984 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 77ms. Found 1 JPA repository interfaces.
2020-09-21 16:34:45.068 INFO 18984 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9003 (http)
2020-09-21 16:34:45.084 INFO 18984 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-09-21 16:34:45.085 INFO 18984 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
2020-09-21 16:34:45.282 INFO 18984 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-09-21 16:34:45.282 INFO 18984 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2110 ms
2020-09-21 16:34:45.560 INFO 18984 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-09-21 16:34:45.576 INFO 18984 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-09-21 16:34:45.789 INFO 18984 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-09-21 16:34:45.865 INFO 18984 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-09-21 16:34:46.106 INFO 18984 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.21.Final
2020-09-21 16:34:46.403 INFO 18984 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-09-21 16:34:46.570 WARN 18984 --- [ main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2020-09-21 16:34:46.677 INFO 18984 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect
2020-09-21 16:34:46.744 INFO 18984 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9003 (http) with context path ''
2020-09-21 16:34:46.747 INFO 18984 --- [ main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-09-21 16:34:47.687 INFO 18984 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-09-21 16:34:47.699 INFO 18984 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-09-21 16:34:48.010 INFO 18984 --- [ main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-09-21 16:34:48.023 INFO 18984 --- [ main] c.e.StudentCrud.StudentCrudApplication : Started StudentCrudApplication in 5.445 seconds (JVM running for 5.976)
2020-09-21 16:35:13.335 INFO 18984 --- [nio-9003-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-09-21 16:35:13.335 INFO 18984 --- [nio-9003-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-09-21 16:35:13.345 INFO 18984 --- [nio-9003-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 10 ms
Get / 2020-09-21 16:35:13.912 ERROR 18984 --- [nio-9003-exec-1] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-9003-exec-1] Exception processing template "index": Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
Комментарии:
1. Что вы делаете, чтобы получить 500? Какова полная ошибка с трассировкой стека из Spring?
2. Вы должны получать полную трассировку стека исключений в журналах вашего сервера, на котором выполняется spring boot. Пожалуйста, добавьте это к вопросу выше
3. я прикрепил журнал ошибок выше, проверьте, я прикрепил полный код по ссылке github выше
4. вы должны записать HTML-страницы в
templates
каталог. переместитьindex.htm
иnew.html
вtemplates
папку5. как написать в нем, сэр, я новичок в этом