这篇文章主要介绍了基于SPRINGBOOT配置文件占位符过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
<强>一、配置文件占位符强>
1, application.properties
server.port=8088 debug=false product.id=ID: $ {random.uuid} product.name=da毛泽东毛 product.weight=$ {random.int} product.fristLinePrice=$ {random.int (500600)} product.endLinePrice=$ {random.int [300400]} product.remark=$ {product.name}
2, SpringbootController
@RestController 公开课SpringBootController { @ value (" $ {product.id} ") 私人字符串id; @ value (" $ {product.name} ") 私人字符串名称; @ value (" $ {product.weight} ") 私人整数重量; @ value (" $ {product.fristLinePrice} ") 私人整数fristLinePrice; @ value (" $ {product.endLinePrice} ") 私人整数endLinePrice; @ value (" $ {product.remark} ") 私人字符串的话; @RequestMapping("/正确的”) 公共字符串getProper () { system . out。println (SpringBootController {+ " id=" + id \“+ +” “name=" +名字+ \” ”,体重=" +重量+ ”,fristLinePrice=" + fristLinePrice + ”,endLinePrice=" + endLinePrice + ”,话=" +备注\“+ +” “}”); 返回“你好!”; } }
3,结果
SpringBootController { id=' id: 188 b528a - 508 f - 44 - aa - 9 - b5e - 43 - c1af7b14e3”, name=' da毛泽东毛', 重量=237719179, fristLinePrice=572, endLinePrice=380, 评论=' da毛泽东毛' }
<强>二,配置文件获取之前的值(如果该值有,直接获取,如果没有使用默认值):此处由于前面的配置中没有product.name,那么他就使用默认值小毛毛强>
server.port=8088 debug=false product.id=ID: $ {random.uuid} product.weight=$ {random.int} product.fristLinePrice=$ {random.int (500600)} product.endLinePrice=$ {random.int [300400]} product.remark=$ {product.name:小毛毛}
SpringBootController { id=' id: fcf731f3 c028 - 452 - a831 a25c1bf41d33”, name=傲恪? 重量=-1450910103, fristLinePrice=584, endLinePrice=357, 评论=小毛毛的 }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。