Dust__ 2019-12-26 15:51 采纳率: 0%
浏览 4118

SpringBoot+Thymeleaf无法访问页面505问题: An error happened during template parsing怎么解决?

报错代码:2019-12-26 15:45:08.541 ERROR 13316 --- [nio-8080-exec-9] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-9] Exception processing template "admin_index": An error happened during template parsing (template: "class path resource [templates/admin_index.html]")

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/admin_index.html]")

Controller类是这样的

@Controller
@RequestMapping("/admin")
public class LoginController {


    @Autowired
    private UserService userService;

    @GetMapping
    public String loginPage() {
        return "admin/login";
    }


    @PostMapping("/login")
    public String login(@RequestParam String username,
                        @RequestParam String password,
                        HttpSession session,
                        RedirectAttributes attributes) {
        User user = userService.checkUser(username, password);
        if (username == "admin"&&password == "111111") {     
            return "admin_index";
        } else {
            attributes.addFlashAttribute("message", "用户名和密码错误");
            return "admin_index";
        }
    }
        //为了方便跳转页面设置账号密码无论对错都跳转到admin_index
}

admin_index.html头文件

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/_fragments :: head(~{::title})">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>博客管理</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
  <link rel="stylesheet" href="../../static/css/me.css">
</head>
<body>

输入账号密码无论对错直接跳500,CSDN上搜到的方法都试过了都没用

  • 写回答

1条回答 默认 最新

  • 「已注销」 2019-12-26 15:55
    关注
     @GetMapping
        public String loginPage() {
            return "redirect:/admin/login";
        }
    controller方法之间跳转需要加redirect
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog