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

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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看