springboot常见写法

 

访问html文件

对于aa.html页面,采用跳转到方式:放在templates目录下时,要加一个thymeleaf依赖,并在controller跳转。

不用跳转到方式: 将依赖去掉,将controler去掉,直接放在static目录下

 

采用devtools进行热部署

热部署指的是springboot在启动后,默认监听classpath路径下的.class文件

不被热部署的文件:    META-INF/maven/     META-INF/resources /            /resources         /static            /public       /templates

可以设置一个触发器,只有某个文件发生改变时,才重启进行热部署

 

读取配置文件注入到属性

第一种情况

1  配置文件 : application.properties

test.domain=www.xxx.net
test.name=springboot

 2 一个普通的java类

@Component
@PropertySource({"classpath:application.properties"})
@ConfigurationProperties(prefix="test")
public class ServerSettings {

//名称
private String name;

private String domain;

}

3  其他的controller类注入bean

@Autowired
private ServerSettings serverSettings;

第二种情况

1  配置文件 : application.properties

web.file.path=/Users/xxxxx/Desktop/

2 在controller类中

@Controller
@PropertySource({"classpath:application.properties"})
public class FileController { 

     @Value("${web.file.path}")
      private String filePath;

}

 

转载于:https://www.cnblogs.com/moris5013/p/9943741.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值