SpringBoot通过后台访问HTML页面

本文章内容主要讲下怎么通过SpringBoot进入HTML页面

1、首先在pom.xml添加对HTML的相关依赖

/**
 * pom.xml文件
 */
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

2、在application.yml文件添加SpringBoot相关配置

spring:
  thymeleaf:
    prefix: classpath:/templates/  
 server: port:8080        
              context-path:"/lmycc"

3、创建HTML文件

/**
 * 路径:resources/templates
 */
第一个HTML页面

Hello Spring Boot!!!

4、在Controller里面写跳转HTML页面方法
@Controller  //注意这里必须为Controller
public class HelloController {
 
    /**
     * 本地访问内容地址 :http://localhost:8080/lmycc/hello
     * @param map
     * @return
     */
    @RequestMapping("/hello")
    public String helloHtml(HashMap<String, Object> map) {
        map.put("hello", "欢迎进入HTML页面");
        return "/index";
    }
}

5、访问页面

好了,这样就可以通过SpringBoot正常访问HTML页面了,快去试试吧!
源码下载地址:http://download.csdn.net/download/sinat_33889619/10038775

本文转载自:https://blog.csdn.net/zty1317313805/article/details/80095687

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值