[英]issue with springboot project : org.thymeleaf.exceptions.TemplateInputException
hey guys 大家好
i have a problem in my java spring boot application 我的Java Spring Boot应用程序中有问题
i've built a simple application and connected it with a database 我建立了一个简单的应用程序并将其与数据库连接
but when i try to make a POST or GET on the data base my program access the database and do any thing i did but show an error 但是,当我尝试在数据库上进行POST或GET时,我的程序访问数据库并执行我所做的任何事情,但显示错误
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "Students", template might not exist or might not be accessible by any of the configured Template Resolvers org.thymeleaf.exceptions.TemplateInputException:解决模板“学生”时出错,模板可能不存在或任何已配置的模板解析器都无法访问
when i make GET i check the Iterable list and it's already get the data from database but doesn't show the data on the localhost it's give me that exception is there any solution for that ? 当我执行GET时,我检查了Iterable列表,它已经从数据库中获取了数据,但是没有在本地主机上显示数据,这给了我例外是否有解决方案? this is my code in controller
这是我在控制器中的代码
@Path("Students")
@Controller
public class studentsController {
@AutoWired
StudentServices st;
@RequestMapping(method = RequestMethod.GET)
public Iterable<Students> getAllStudents() {
Iterable<Students> list = st.getAllStudents();
return list
}
With @Controller you are defining a Model-View-Controller (MVC) endpoint for returning your view templates. 使用@Controller,您可以定义一个Model-View-Controller(MVC)端点来返回视图模板。 So with
Iterable<Students>
Spring is looking for a Students
template in your src/main/resources/templates
folder because it is interpreted as a View name. 因此,使用
Iterable<Students>
Spring会在src/main/resources/templates
文件夹中寻找“ Students
模板,因为它被解释为“视图”名称。
If you want to create a REST endpoint which returns a list of Student objects you should use @RestController
at your class which adds the Spring annotation @RequestBody
automatically. 如果要创建一个返回学生对象列表的REST端点,
@RestController
在类中使用@RestController
,该类会自动添加Spring批注@RequestBody
。
Furthermore @Path("XYZ")
should be replaced with @RequestMapping("XYZ")
in Spring and @AutoWired
with @Autowired
. 此外,Spring中的
@Path("XYZ")
应该替换为@RequestMapping("XYZ")
,而@AutoWired
应该替换为@Autowired
。
An working example could look like the following: 一个有效的示例如下所示:
@RequestMapping("/students")
@RestController
public class StudentsController {
@Autowired
StudentServices st;
@RequestMapping(value="/", method = RequestMethod.GET)
public Iterable<Students> getAllStudents() {
Iterable<Students> list = st.getAllStudents();
return list
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.