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

 

posted @ 2021-03-14 21:28  poterliu  阅读(1050)  评论(0编辑  收藏  举报