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;

}

 

posted @ 2018-11-11 21:43  踏月而来  阅读(950)  评论(0编辑  收藏  举报