zoukankan      html  css  js  c++  java
  • Spring使用@Value注解各种类型的值

    在application.properties写入下面代码

    test.boolean=true
    test.string=abc
    test.integer=123
    test.long=123
    test.float=1.2345678123456
    test.double=1.2345678123456
    test.array=1,3,4,5,6,1,2,3
    test.list=1,3,4,5,6,1,2,3
    test.set=1,3,4,5,6,1,2,3
    test.map={name:"张三", age:18}
     

    使用junit进行测试

    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = {ApplicationBootstrap.class})
    public class DemoTest {

    @Value("${test.boolean}")
    private Boolean testBoolean;

    @Value("${test.string}")
    private String testString;

    @Value("${test.integer}")
    private Integer testInteger;

    @Value("${test.long}")
    private Long testLong;

    @Value("${test.float}")
    private Float testFloat;

    @Value("${test.double}")
    private Double testDouble;

    @Value("#{'${test.array}'.split(',')}")
    private String[] testArray;

    @Value("#{'${test.list}'.split(',')}")
    private List<String> testList;

    @Value("#{'${test.set}'.split(',')}")
    private Set<String> testSet;

    @Value("#{${test.map}}")
    private Map<String, Object> testMap;

    }

  • 相关阅读:
    单例类
    日期类2
    日历类
    日期转换类
    抓取网页内容并截图
    关于计时器与多线程
    让页面上图片不变形
    Thread 调用方法的方式
    语音放大缩小
    阻止Enter键回发到服务端Asp.net
  • 原文地址:https://www.cnblogs.com/liangblog/p/12690815.html
Copyright © 2011-2022 走看看