SpringBoot入门系列~SpringBoot属性配置1
前一章节主要是SpringBoot的简单介绍与项目的创建,这章节主要配置一些指定的属性,主要在application.properties 属性配置文件配置,具体实现看代码注释
- 配置系统属性
#指定项目访问的端口,默认是8080端口 server.port=8088 #指定访问路径不是根目录,需要加项目名 server.context-path=/SpringBootChapter1
启动访问: http://127.0.0.1:8088/SpringBootChapter1/showMsg
- 配置自定义属性:key=value的形式
- 在代码中通过注解获取
- 定义方法访问
/** * 测试从属性配置文件取值操作 * @Title: customMessager * @author sunt * @date 2017年11月7日 * @return String * @throws UnsupportedEncodingException */ @RequestMapping("/customMessager") @ResponseBody public String customMessager() throws UnsupportedEncodingException { return customMessager; }
页面访问:http://127.0.0.1:8088/SpringBootChapter1/customMessager
-
/** * 测试从属性配置文件取值操作 * @Title: customMessager * @author sunt * @date 2017年11月7日 * @return String * @throws UnsupportedEncodingException */ @RequestMapping("/customMessager") @ResponseBody public String customMessager() throws UnsupportedEncodingException { //解决中文乱码问题 return new String(customMessager.getBytes("iso-8859-1"), "utf-8"); }
最新同步更新地址:https://www.sunnyblog.top/
感谢您花时间阅读此篇文章,如果您觉得这篇文章你学到了东西也是为了犒劳下博主的码字不易不妨打赏一下吧,让博主能喝上一杯咖啡,在此谢过了!
如果您觉得阅读本文对您有帮助,请点一下左下角“推荐”按钮,您的“推荐”将是我最大的写作动力!另外您也可以选择【关注我】,可以很方便找到我!
本文版权归作者和博客园共有,来源网址:https://www.cnblogs.com/sunny1009 欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利!

浙公网安备 33010602011771号