SpringBoot获取maven打包时间的两种方式
更新时间:2024年05月06日 10:22:15 作者:指尖‖舞者
这篇文章主要介绍了SpringBoot获取maven打包时间的两种方式,文章通过代码示例给大家讲解的非常详细,对大家的学习或工作有一定的帮助,需要的朋友可以参考下
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区
*/
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区
*/
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());
}
到此这篇关于SpringBoot获取maven打包时间的两种方式的文章就介绍到这了,更多相关SpringBoot maven打包时间内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
详解在Spring-Boot中实现通用Auth认证的几种方式
这篇文章主要介绍了详解在Spring-Boot中实现通用Auth认证的几种方式,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-07-07
解决RestTemplate加@Autowired注入不了的问题
这篇文章主要介绍了解决RestTemplate加@Autowired注入不了的问题,具有很好的参考价值,希望对大家有所帮助。2021-08-08
SpringMVC实现RESTful风格:@PathVariable注解的使用方式
这篇文章主要介绍了SpringMVC实现RESTful风格:@PathVariable注解的使用方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2021-11-11
RestTemplate发送form-data请求上传rul资源文件及对象参数方式
这篇文章主要介绍了RestTemplate发送form-data请求上传rul资源文件及对象参数方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2024-01-01


最新评论