[英]org.thymeleaf.exceptions.TemplateInputException: Spring Boot
I'm creating an eductional system for learning through games and I'm using android as a front-end and Spring boot as a back-end and I'm creating a service for creating a course and I take the data from the front end through this link http://localhost:8090/addcourse/{teacherID}
but when I run the program it gives me an error and I don't know ho to solve it 我正在创建一个通过游戏学习的教育系统,我使用android作为前端,Spring启动作为后端,我正在创建一个创建课程的服务,我从前端获取数据通过这个链接
http://localhost:8090/addcourse/{teacherID}
但是当我运行程序时它给了我一个错误,我不知道怎么解决它
Error Message: Error resolving template "addcourse/2", template might not exist or might not be accessible by any of the configured Template Resolvers 错误消息:解析模板“addcourse / 2”时出错,模板可能不存在或任何已配置的模板解析器可能无法访问
Service: 服务:
@RequestMapping(method = RequestMethod.POST, value = "/addcourse/{teacherId}")
public Map<String,String> createCourse(@RequestBody Course course, @PathVariable int teacherId) {
Map<String,String> data = new HashMap<>();
User Teacher = userRep.findOne(teacherId);
if(Teacher.getTeacherCode()=="TA123") {
course.setUser(Teacher);
courseRep.save(course);
data.put("check", "true");
Course course2 = courseRep.findByCourseName(course.getCourseName());
data.put("ID", course2.getCourseID()+"");
return data;
}
data.put("check", "false");
return data;
}
You are returning a Map
from your controller which does not give Spring MVC a hint which view name it should use. 您正在从控制器返回一个
Map
,它不会给Spring MVC一个提示,它应该使用哪个视图名称。 So it deduces it from the URL used to access the controller, in this case it's addcourse/2
. 所以它从用于访问控制器的URL中推断出来,在这种情况下它是
addcourse/2
。 Probably you don't have a view (a Thymeleaf template) per teacher; 可能每个老师都没有视图(Thymeleaf模板); I suppose that you have a Thymeleaf view called
addcourse
. 我想你有一个名为
addcourse
的Thymeleaf视图。
Try returning view name explicitly: 尝试显式返回视图名称:
return new ModelAndView("addcourse", data);
instead of 代替
return data;
"addcourse"
has to be changed to your real template name. "addcourse"
更改为您的真实模板名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.