欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot獲取maven打包時間的兩種方式

 更新時間:2024年05月06日 10:22:15   作者:指尖‖舞者  
這篇文章主要介紹了SpringBoot獲取maven打包時間的兩種方式,文章通過代碼示例給大家講解的非常詳細(xì),對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下

springboot 獲取maven打包時間

pom

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.13.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>

		<!--指定時間格式 -->
		<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
		<!--maven.build.timestamp保存了maven編譯時間戳 -->
		<timestamp>${maven.build.timestamp}</timestamp>

	</properties>


	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!--lombok -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
	</dependencies>


	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>

		<resources>
			<resource>
				<directory>src/main/resources/</directory>
				<filtering>true</filtering>
			</resource>
		</resources>
	</build>

方式一

maven.properties

# maven打包時間
maven.package_time=@timestamp@

MavenProperties

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import lombok.Data;

@Configuration
@ConfigurationProperties(prefix = "maven", ignoreUnknownFields = false)
@PropertySource(value= "classpath:config/maven.properties",encoding = "utf-8")
@Data
@Component
public class MavenProperties {
    /**maven打包時間*/
    private String package_time;
}

測試

	@Resource
    private MavenProperties mavenProperties;
	
	@GetMapping("/mavenTime")
	public String ah() {
		return "最新打包時間:"+modifyTime(packageTime);
	}
	
	/**
     * 修改時間為東8區(qū)
     */
    public String modifyTime(String date) {
        Date oldDate=null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            oldDate = simpleDateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(oldDate);
        calendar.add(Calendar.HOUR_OF_DAY, +8);
        return simpleDateFormat.format(calendar.getTime());
    }	

方式二

application.yml

maven:
  package_time: '@timestamp@' # maven打包時間

測試

@Value("${maven.package_time}")
	private String packageTime;
	
	@GetMapping("/mavenTime")
	public String ah() {
		return "最新打包時間:"+modifyTime(packageTime);
	}
	
	/**
     * 修改時間為東8區(qū)
     */
    public String modifyTime(String date) {
        Date oldDate=null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            oldDate = simpleDateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(oldDate);
        calendar.add(Calendar.HOUR_OF_DAY, +8);
        return simpleDateFormat.format(calendar.getTime());
    }

到此這篇關(guān)于SpringBoot獲取maven打包時間的兩種方式的文章就介紹到這了,更多相關(guān)SpringBoot maven打包時間內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論