Spring boot可实现Web开发功能,简化框架的配置,可以快速开发,以下是精简的步骤:
1.使用Maven构建项目,Artifact Id选择maven-archetype-quickstart
2.添加pom依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    <version>2.0.2.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.0.2.RELEASE</version>
</dependency>
<dependency>

3.新建src/main/resources/templates包结构
4.Spring boot启动,页面前后台交互

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@SpringBootApplication
public class App 
{
    @RequestMapping("/getPage")
    public String getMyPage() {
        return "myPage";
    }
    public static void main( String[] args )
    {
        new SpringApplication(App.class).run(args);
    }
}

main方法启动Spring boot项目,getMyPage方法返回myPage字符串,thymeleaf会直接找到templates包下myPage.html页面。
5.最终效果
项目启动后,访问http://localhost:8080/getPage,返回myPage.html页面信息

更多推荐

Spring Boot实现页面前后台交互Web功能