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

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页面信息
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值