springboot + shiro 使用html页面遇到的问题

建了一个springboot的项目 想结合shiro做练习

页面使用html。通过controller跳转到html页面的时候,报405错误。405就是get和post提交方式的问题。

但是查看form表单提交和controller的处理方法后确认不是405的问题。

@RequestMapping("/loginUser")
    public String loginUser(@RequestParam("username")String username,
                            @RequestParam("password")String password,
                            HttpSession session){
        UsernamePasswordToken token=new UsernamePasswordToken(username,password);
        Subject subject= SecurityUtils.getSubject();
        try {
            subject.login(token);
            User user= (User) subject.getPrincipal();
            session.setAttribute("user",user);
            return "index";
        }catch (Exception e){
            e.printStackTrace();
            return "login";
        }
    }


因为都是post提交 所以405肯定是其他问题触发的。

后来问了别人后 发现springboot要访问html需要先整合thymeleaf的maven包 然后进行配置。

于是pom文件添加依赖


   org.springframework.boot
   spring-boot-starter-thymeleaf

application.property里面配置(我的页面没有放在resource的templates路径下,而是放在了webapp下的page里面 模仿mvc那种模式)

#thymeleaf
spring.thymeleaf.prefix=/pages/

添加完成后 本以为可以正常运行了,但是又报错了 说html页面的标签不完整。

百度之后发现 thymeleaf对html标签的要求很高 必须是闭合的标签。

但是又不想让它验证这么严格,于是在property文件里配置

#去掉thymeleaf的严格的模板校验
spring.thymeleaf.mode=LEGACYHTML5

在pom里面添加这个依赖


   net.sourceforge.nekohtml
   nekohtml
   1.9.22

上面这个依赖是我配置完property文件后报的错误。这些都配置完成后就一切ok了

你可能感兴趣的:(springboot + shiro 使用html页面遇到的问题)