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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM