简体   繁体   English

org.thymeleaf.exceptions.TemplateInputException:Spring Boot

[英]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.

相关问题 我的spring-boot应用程序给出以下错误“ org.thymeleaf.exceptions.TemplateInputException:” - My spring-boot app gives the following error “org.thymeleaf.exceptions.TemplateInputException:” Thymeleaf:org.thymeleaf.exceptions.TemplateInputException - Thymeleaf : org.thymeleaf.exceptions.TemplateInputException 如何调试org.thymeleaf.exceptions.TemplateInputException? - How to debug org.thymeleaf.exceptions.TemplateInputException? springboot项目的问题:org.thymeleaf.exceptions.TemplateInputException - issue with springboot project : org.thymeleaf.exceptions.TemplateInputException Thyemleaf 嵌套迭代触发器 org.thymeleaf.exceptions.TemplateInputException - Thyemleaf nested iteration triggers org.thymeleaf.exceptions.TemplateInputException org.thymeleaf.exceptions.TemplateInputException:解决片段错误:无法解析模板或片段 - org.thymeleaf.exceptions.TemplateInputException: Error resolving fragment: template or fragment could not be resolved org.thymeleaf.exceptions.TemplateInputException:异常分析文档:template =“ login”,第36行-第3列 - org.thymeleaf.exceptions.TemplateInputException: Exception parsing document: template=“login”, line 36 - column 3 如何摆脱 org.thymeleaf.exceptions.TemplateInputException: 同时使用 thymeleaf 表达式以引导卡的形式打印数据? - how to get rid of org.thymeleaf.exceptions.TemplateInputException: while using thymeleaf expression to print data in form of bootstrap cards? Spring 启动测试 Thymeleaf org.thymeleaf.exceptions.TemplateProcessingException - Spring Boot Testing Thymeleaf org.thymeleaf.exceptions.TemplateProcessingException Spring启动TemplateInputException - Spring boot TemplateInputException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM