idea springboot 整合thymeleaf

项目结构:

idea springboot 整合thymeleaf_第1张图片

pom.xml:引入thymeleaf与springboot的整合包

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

springboot启动类:

package com.lucifer.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringbootShiroApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootShiroApplication.class, args);
    }
}

 

 controller类:

package com.lucifer.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * @author: Lucifer
 * @create: 2018-09-06 16:19
 * @description:
 **/

@Controller
public class UserController {

    /**
     * 测试thymeleaf
     * @param model
     * @return
     */
    @RequestMapping("/testThymeleaf")
    public String testThymeleaf(Model model){
        //将数据存入model
        model.addAttribute("name","路西法");
        //返回test.html
        return "test";
    }
}

test.html:




    
    测试thymeleaf的使用


    

ps:刚开始idea中html直接用thymeleaf表达式,会出现红线,这时你可以用Alt+Enter,html会引入

,此时红线消失。

启动项目,

idea springboot 整合thymeleaf_第2张图片

 

成功!!!

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(SpringBoot技术篇)