Springboot @Value使用代碼實(shí)例
這篇文章主要介紹了Springboot @Value使用代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
entity.Book
package com.draymonder.amor.entity; import java.util.List; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @Component public class Book { @Value("${book.name}") private String name; @Value("${book.author}") private String author; @Value("${book.price}") private Double price; @Value("#{'${book.love}'.split(',')}") private List<String> love; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public Double getPrice() { return price; } public void setPrice(Double price) { this.price = price; } @Override public String toString() { return "Book{" + "name='" + name + '\'' + ", author='" + author + '\'' + ", price=" + price + ", love=" + love + '}'; } }
web.BookController
package com.draymonder.amor.web; import com.draymonder.amor.entity.Book; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class BookController { @Autowired Book book; @GetMapping("/book") public String book() { return book.toString(); } }
resources/applcation.yml
server: port: 8080 book: name: amor author: draymonder price: 50 love: a, b, c
訪問url localhost:8080/book
展示結(jié)果
Book{name='amor', author='draymonder', price=50.0, love=[a, b, c]}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JAVA中讀取文件(二進(jìn)制,字符)內(nèi)容的幾種方法總結(jié)
本篇文章主要介紹了JAVA中讀取文件(二進(jìn)制,字符)內(nèi)容的方法總結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02java并發(fā)編程工具類JUC之ArrayBlockingQueue
類ArrayBlockingQueue是BlockingQueue接口的實(shí)現(xiàn)類,它是有界的阻塞隊(duì)列,內(nèi)部使用數(shù)組存儲(chǔ)隊(duì)列元素,通過代碼給大家說明如何初始化一個(gè)ArrayBlockingQueue,并向其中添加一個(gè)對象,對java并發(fā)編程工具類ArrayBlockingQueue相關(guān)知識(shí)感興趣的朋友一起看看吧2021-05-05Java?SM2加密相關(guān)實(shí)現(xiàn)與簡單原理詳解
SM2算法可以用較少的計(jì)算能力提供比RSA算法更高的安全強(qiáng)度,而所需的密鑰長度卻遠(yuǎn)比RSA算法低,這篇文章主要給大家介紹了關(guān)于Java?SM2加密相關(guān)實(shí)現(xiàn)與簡單原理的相關(guān)資料,需要的朋友可以參考下2024-01-01MyBatis超詳細(xì)講解如何實(shí)現(xiàn)分頁功能
MyBatis-Plus?是一個(gè)?Mybatis?增強(qiáng)版工具,在?MyBatis?上擴(kuò)充了其他功能沒有改變其基本功能,為了簡化開發(fā)提交效率而存在,本篇文章帶用它實(shí)現(xiàn)分頁功能2022-03-03Java正則表達(dá)式之split()方法實(shí)例詳解
這篇文章主要介紹了Java正則表達(dá)式之split()方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了split方法的功能、使用方法及相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-03-03J2EE驗(yàn)證碼圖片如何生成和點(diǎn)擊刷新驗(yàn)證碼
這篇文章主要介紹了J2EE如何生成驗(yàn)證碼圖片如何生成,如何點(diǎn)擊刷新驗(yàn)證碼的相關(guān)方法,感興趣的小伙伴們可以參考一下2016-04-04java多線程編程之使用thread類創(chuàng)建線程
在Java中創(chuàng)建線程有兩種方法:使用Thread類和使用Runnable接口。在使用Runnable接口時(shí)需要建立一個(gè)Thread實(shí)例2014-01-01