这篇文章主要介绍了Springboot @ value使用代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
<强> entity.Book 强>
包com.draymonder.amor.entity; 进口并不知道; 进口org.springframework.beans.factory.annotation.Value; 进口org.springframework.boot.context.properties.ConfigurationProperties; 进口org.springframework.stereotype.Component; @ component 公开课书{ @ value (" $ {book.name} ") 私人字符串名称; @ value (" $ {book.author} ") 私人字符串作者; @ value (" $ {book.price} ") 私人双价格; @ value (" # {' $ {book.love} ' .split (" ")}”) 私人List爱; 公共字符串getName () { 返回名称; } 公共空间setName(字符串名称){ this.name=名称; } 公共字符串getAuthor () { 返回作者; } 公共空间setAuthor(字符串作者){ 这一点。作者=作者; } 公共双getPrice () { 回报价格; } 公共空间setPrice(双价格){ 这一点。价格=价格; } @Override 公共字符串toString () { {" + "书还回来 “name=" +名字+ \”=?”,作者作者\“+ +” ”,价格=" +价格+ ”,爱情=" +爱+ '} '; } }
<强> web.BookController 强>
包com.draymonder.amor.web; 进口com.draymonder.amor.entity.Book; 进口org.springframework.beans.factory.annotation.Autowired; 进口org.springframework.web.bind.annotation.GetMapping; 进口org.springframework.web.bind.annotation.RestController; @RestController 公开课BookController { @ autowired 书书; @GetMapping(“/书”) 公共字符串书(){ 返回book.toString (); } }
<强>资源/applcation.yml 强>
服务器: 端口:8080 书: 名称:埃莫 作者:draymonder 价格:50 爱:a, b, c
<强>访问url localhost: 8080/书
强>
<>强展示结果强>
作者书{name=鞍?癲raymonder”,价格=50.0,爱情=[a, b, c]}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。