SpringBoot实例①SpringBoot+bootstrap+thymeleaf实现简单页面

首先,新建一个springboot项目。具体步骤参考之前的SpringBoot入门文章,有详细图文介绍。

目录结构:

SpringBoot实例①SpringBoot+bootstrap+thymeleaf实现简单页面_第1张图片


package com.cxl.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String inxdex(){
        return "Hello world!Hello CXL!!";
    }
}
package com.cxl.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class WelcomeController {

    // inject via application.properties
    @Value("${welcome.message:test}")
    private String message = "Hello World";

    @RequestMapping("/")
    public String welcome(Map model) {
        model.put("message", this.message);
        return "welcome.html";
    }

}

默认项

package com.cxl;

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

@SpringBootApplication
public class Demochapter1Application {

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


main.css

h1{
    font-size: 20pt;
}
h2{
    font-size: 16pt;
}




    Spring Boot Thymeleaf Hello World示例
    

    

    






Spring Boot Web Thymeleaf示例

application.properties

welcome.message: Hello, Spring Boot


pom



    4.0.0

    com.cxl
    demochapter1
    0.0.1-SNAPSHOT
    jar

    demochapter1
    Demo project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.2.RELEASE
         
    

    
        UTF-8
        UTF-8
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        

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

        
        
            org.springframework.boot
            spring-boot-devtools
            true
        

        
        
            org.webjars
            bootstrap
            3.3.7
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



友情提示:pom里的jar包一定要添加完整了。才能正常显示。否则就算不报错。也无法显示出来。特别是这个:thymeleaf

SpringBoot实例①SpringBoot+bootstrap+thymeleaf实现简单页面_第2张图片

正常显示的网页效果:

SpringBoot实例①SpringBoot+bootstrap+thymeleaf实现简单页面_第3张图片

你可能感兴趣的:(springboot学习)