zoukankan      html  css  js  c++  java
  • springboot thymeleaf 打包成jar包后报错 template might not exist or might not be accessible by any of the configured Template Resolvers

    解决方案:

    spring.thymeleaf.cache=false
    spring.thymeleaf.prefix=classpath:/templates/
    spring.thymeleaf.suffix=.html


    改成

    spring.thymeleaf.cache=false
    spring.thymeleaf.prefix=classpath:/templates
    spring.thymeleaf.suffix=.html

    Controller 写法

    import com.poterliu.entity.User;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.Map;
    
    @Controller
    public class IndexController {
    
        /**
         * 测试 thymeleaf
         * http://127.0.0.1:8080/home
         * @param model
         * @return
         */
        @GetMapping("home")
        public String thymeleafDemo(Model model) {
            User user = new User();
            user.setUsername("jack");
            user.setPassword("112233");
            user.setHobbies(Arrays.asList(new String[]{"singing", "dancing", "football"}));
            Map<String, String> maps = new HashMap<>();
            maps.put("1", "o");
            maps.put("2", "g");
            maps.put("3", "a");
            maps.put("4", "j");
            user.setSecrets(maps);
            model.addAttribute("user", user);
            return "/thymeleafDemo";
        }
    
        @GetMapping("")
        public String index(Model model) {
            return "/index";
        }
    }

    参考:

    https://blog.csdn.net/qq_31638493/article/details/81207595

    https://www.cnblogs.com/kinome/p/11509248.html

  • 相关阅读:
    XML 命名空间
    XML Schema验证
    java 解析XML文档
    Java线程:创建与启动
    CCF-CSP 201312-5 I'm stuck !
    memset函数用法
    C++的字符串多行输入
    OS复习1
    os复习2
    javamail编程2
  • 原文地址:https://www.cnblogs.com/poterliu/p/14534323.html
Copyright © 2011-2022 走看看