0
点赞
收藏
分享

微信扫一扫

springBoot访问静态资源

新建项目

springBoot访问静态资源_spring

 

springBoot访问静态资源_html_02

 

 springBoot访问静态资源_spring_03

 

 springBoot访问静态资源_java_04

 

我们把一张图片放在static的目录下

springBoot访问静态资源_java_05

 

 编写App.java启动类

springBoot访问静态资源_html_06

 

App.java

package com.gongspringstatic.app;

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

/**
* SpringBoot 启动类
* @author Administrator
*
*/
@SpringBootApplication
public class App {

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

 

 运行启动类

springBoot访问静态资源_java_07

 

 springBoot访问静态资源_html_08

 

 在浏览器访问

springBoot访问静态资源_java_09

 

 新建一个index.html

springBoot访问静态资源_spring_10

 

 springBoot访问静态资源_html_11

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>静态资源访问方式一</title>
</head>
<body>
静态资源访问方式一
</body>
</html>

 

 

启动App.java

springBoot访问静态资源_spring_12

 

 打开浏览器访问

springBoot访问静态资源_java_13

 

 新建images包,并把java.jpg放进去

 springBoot访问静态资源_spring_14

 

在index.html中添加一下语句

springBoot访问静态资源_java_15

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>静态资源访问方式一</title>
</head>
<body>
静态资源访问方式一
<hr/>
<img alt="" src="images/java.jpg">
</body>
</html>

 

 

启动App.java类

springBoot访问静态资源_html_16

 

 springBoot访问静态资源_java_17

 

 

 在浏览器中访问

springBoot访问静态资源_java_18

 

 

 

 

 

 

访问静态资源的第二种方法

 我们重新创建一个项目

springBoot访问静态资源_html_19

springBoot访问静态资源_html_20

 

 springBoot访问静态资源_spring_21

 

 springBoot访问静态资源_spring_22

 

 在main目录下创建webapp目录,名称必须叫webapp

 springBoot访问静态资源_html_23

 

把上一个项目的static目录下的内容复制过来

springBoot访问静态资源_spring_24

 

 同时把app.java类也复制过来

springBoot访问静态资源_java_25

 

 运行app.java类

springBoot访问静态资源_html_26

 

springBoot访问静态资源_java_27

 

 打开浏览器,同样能访问到

springBoot访问静态资源_html_28

 

举报

相关推荐

0 条评论