SpringBoot獲取maven打包時(shí)間的兩種方式
springboot 獲取maven打包時(shí)間
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>
<!--指定時(shí)間格式 -->
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
<!--maven.build.timestamp保存了maven編譯時(shí)間戳 -->
<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打包時(shí)間 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打包時(shí)間*/
private String package_time;
}
測試
@Resource
private MavenProperties mavenProperties;
@GetMapping("/mavenTime")
public String ah() {
return "最新打包時(shí)間:"+modifyTime(packageTime);
}
/**
* 修改時(shí)間為東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打包時(shí)間
測試
@Value("${maven.package_time}")
private String packageTime;
@GetMapping("/mavenTime")
public String ah() {
return "最新打包時(shí)間:"+modifyTime(packageTime);
}
/**
* 修改時(shí)間為東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打包時(shí)間的兩種方式的文章就介紹到這了,更多相關(guān)SpringBoot maven打包時(shí)間內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Mybatis使用XML實(shí)現(xiàn)動(dòng)態(tài)sql的示例代碼
當(dāng)編寫 MyBatis 中復(fù)雜動(dòng)態(tài) SQL 語句時(shí),使用 XML 格式是一種非常靈活的方式,本文主要為大家詳細(xì)介紹了Mybatis使用XML實(shí)現(xiàn)動(dòng)態(tài)sql的具體方法,需要的可以參考下2023-12-12
詳解在Spring-Boot中實(shí)現(xiàn)通用Auth認(rèn)證的幾種方式
這篇文章主要介紹了詳解在Spring-Boot中實(shí)現(xiàn)通用Auth認(rèn)證的幾種方式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07
關(guān)于Springboot在新增和修改下上傳圖片并顯示的問題
這篇文章主要介紹了關(guān)于Springboot在新增和修改下上傳圖片并顯示的問題及解決方法,在這里 springboot中已經(jīng)內(nèi)嵌了上傳圖片的依賴包,因此不需要再添加額外依賴,具體實(shí)現(xiàn)代碼跟隨小編一起看看吧2021-04-04
解決RestTemplate加@Autowired注入不了的問題
這篇文章主要介紹了解決RestTemplate加@Autowired注入不了的問題,具有很好的參考價(jià)值,希望對大家有所幫助。2021-08-08
SpringMVC實(shí)現(xiàn)RESTful風(fēng)格:@PathVariable注解的使用方式
這篇文章主要介紹了SpringMVC實(shí)現(xiàn)RESTful風(fēng)格:@PathVariable注解的使用方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11
學(xué)習(xí)Java模擬實(shí)現(xiàn)百度文檔在線瀏覽
這片文章介紹了如何使用Java模擬實(shí)現(xiàn)百度文檔在線瀏覽,文章思路清晰,需要的朋友可以參考下2015-07-07
IDEA斷點(diǎn)調(diào)試,斷點(diǎn)不起作用的解決
這篇文章主要介紹了IDEA斷點(diǎn)調(diào)試,斷點(diǎn)不起作用的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
RestTemplate發(fā)送form-data請求上傳rul資源文件及對象參數(shù)方式
這篇文章主要介紹了RestTemplate發(fā)送form-data請求上傳rul資源文件及對象參數(shù)方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01

