zoukankan      html  css  js  c++  java
  • Spring Boot系列教程四:配置文件详解properties

    一.配置随机数,使用随机数

    在application.properties文件添加配置信息

    #32位随机数
    woniu.secret=${random.value}
    #随机整数
    woniu.number=${random.int}
    #指定范围随机数
    woniu.limitnumber=${random.int[0,9]}

    controller类中使用这些随机数

    package com.woniu.controller;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping(value=("/web"))
    public class WebController {
    
    	@Value(value="${woniu.secret}")
    	private String uuid;
    	
    	@Value(value="${woniu.number}")
    	private int randomID;
    	
    	@Value(value="${woniu.limitnumber}")
    	private int limitnumber;
    	
    	
    	@RequestMapping(value="/index")
    	public Map<String, Object> Index(){
    		Map<String, Object> map = new HashMap<String, Object>();
    		map.put("uuid", uuid);
    		map.put("randomID", randomID);
    		map.put("limitnumber", limitnumber);
    		return map;
    	}
    }

    二.属性占位符

    使用application.properties配置文件中先前定义的值

    woniu.name="woniu"
    woniu.desc=${woniu.name} is a domain name

    三.application.properties文件的优先级


    相同的配置信息在配置在application.properties中,优先级高的生效

    四.其他配置介绍

    #配置tomcat的端口
    server.port=8080
    
    #时间格式化
    spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
    
    #时区设置
    spring.jackson.time-zone=Asia/Chongqing

    工程springboot_properties下载地址:点击打开链接
    spring boot讨论群:611262656,一键加群:点击加群
    更多技术文章请关注微信公众号“Java架构师之路”:


  • 相关阅读:
    AT+CNMI的使用
    oracle 触发器及游标的使用
    索引优缺点
    SQL Server里的主键、唯一性约束、聚集索引
    C++中使用内存映射文件处理大文件
    oracle 学习笔记
    香干炒肉丝
    如何将数据导入到 SQL Server Compact Edition 数据库中
    解决ORACLE密码遗忘
    Office 2003 主 Interop 程序集的安装和使用
  • 原文地址:https://www.cnblogs.com/woniu201/p/11694639.html
Copyright © 2011-2022 走看看