springboot(4)访问html

1.想要令后端能跳转一个html页面,首先要在pom.xml中加入一个依赖

        <!-- thymeleaf依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

2.springboot项目目录

main-resources-static是放置css,js,image等文件的,

main-resources-templates是放置html文件的。

按照规则放置文件并加入thymeleaf依赖后,后端便可以去访问html文件

3.在controller层定义一个专门用来跳转网页的controller(.java),格式如下

@Controller//必需注解
public class MusicController {

    //访问localhost:8080/  时跳转hello.html
    @RequestMapping("/")//访问网页路径

    public String hello(){//名字没什么用

        return "hello";//跳转的html

    }    


    //访问localhost:8080/exit时跳转exit.html
    @RequestMapping("/exit")
    public String exit(){
        return "exit";
    }
}

4.访问访问localhost:8080/时就可以看到了

5.外接样式表路径写法

存放路径,要按上述规则存放到static中,链接会直接访问到static

html路径写法:

<html>
<head>
    <link href="css/hello.css" rel="stylesheet" type="text/css">
</head>
<body>
<div>
    这里是hello.html
</div>
</body>
</html>

css:

body{
    background-color:black;
}
div{
    background-color:blue;
}

效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值