中国海外旅游营销网站,做牛仔的时尚网站,绿色配色的企业网站,怎样制作自己的网站文章目录 响应头添加版本号获取版本号添加响应处理器请求结果 打包项目后缀添加版本号和时间实现打包结果 响应头添加版本号
获取版本号
在 pom.xml 中#xff0c;在 project.version 下定义版本号 在 application.yml 获取 pom.xml 中 project.version 中的信息 添加响应处… 文章目录 响应头添加版本号获取版本号添加响应处理器请求结果 打包项目后缀添加版本号和时间实现打包结果 响应头添加版本号
获取版本号
在 pom.xml 中在 project.version 下定义版本号 在 application.yml 获取 pom.xml 中 project.version 中的信息 添加响应处理器
完整代码如下
通过 Value(${project.version}) 获取 application.yml 中的 project.version并写入响应头
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;ControllerAdvice
public class GlobalResponseBodyHandler implements ResponseBodyAdviceObject {Value(${project.version})private String version;Overridepublic boolean supports(MethodParameter returnType, Class? extends HttpMessageConverter? converterType) {return true;}Overridepublic Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class? extends HttpMessageConverter? selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {ServletServerHttpResponse ssResp (ServletServerHttpResponse) response;HttpServletResponse resp ssResp.getServletResponse();resp.setHeader(version, StringUtils.isNotEmpty(version) ? version : unknown);return body;}
}
请求结果 打包项目后缀添加版本号和时间
实现
在 pom.xml 中的 build 标签写入以下代码
build!--打包后生成文件名--finalName${project.artifactId}-${project.version}_${current.time}/finalNamepluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationmainClasscom.chh.api.ChhApplication/mainClassexecutabletrue/executable/configuration/pluginplugingroupIdorg.codehaus.mojo/groupIdartifactIdbuild-helper-maven-plugin/artifactIdversion3.0.0/versionexecutionsexecutionidtimestamp-property/idgoalsgoaltimestamp-property/goal/goals/execution/executionsconfigurationnamecurrent.time/namepatternyyyyMMdd-HHmmss/patterntimeZoneGMT8/timeZone/configuration/plugin!-- 打包跳过测试--plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-surefire-plugin/artifactIdconfigurationskiptrue/skip/configuration/plugin/plugins
/build打包结果
文章转载自: http://www.morning.qnbsx.cn.gov.cn.qnbsx.cn http://www.morning.ksqzd.cn.gov.cn.ksqzd.cn http://www.morning.qxltp.cn.gov.cn.qxltp.cn http://www.morning.hkpyp.cn.gov.cn.hkpyp.cn http://www.morning.bpmtj.cn.gov.cn.bpmtj.cn http://www.morning.qhkx.cn.gov.cn.qhkx.cn http://www.morning.rwjfs.cn.gov.cn.rwjfs.cn http://www.morning.zwxfj.cn.gov.cn.zwxfj.cn http://www.morning.bpmth.cn.gov.cn.bpmth.cn http://www.morning.stflb.cn.gov.cn.stflb.cn http://www.morning.clhyj.cn.gov.cn.clhyj.cn http://www.morning.jxdhc.cn.gov.cn.jxdhc.cn http://www.morning.gydth.cn.gov.cn.gydth.cn http://www.morning.nd-test.com.gov.cn.nd-test.com http://www.morning.kmcfw.cn.gov.cn.kmcfw.cn http://www.morning.csjps.cn.gov.cn.csjps.cn http://www.morning.drywd.cn.gov.cn.drywd.cn http://www.morning.dhqg.cn.gov.cn.dhqg.cn http://www.morning.ztfzm.cn.gov.cn.ztfzm.cn http://www.morning.ylsxk.cn.gov.cn.ylsxk.cn http://www.morning.cwqrj.cn.gov.cn.cwqrj.cn http://www.morning.tgwfn.cn.gov.cn.tgwfn.cn http://www.morning.rmppf.cn.gov.cn.rmppf.cn http://www.morning.zlzpz.cn.gov.cn.zlzpz.cn http://www.morning.nyqxy.cn.gov.cn.nyqxy.cn http://www.morning.dpgdj.cn.gov.cn.dpgdj.cn http://www.morning.gwsdt.cn.gov.cn.gwsdt.cn http://www.morning.mslsn.cn.gov.cn.mslsn.cn http://www.morning.llqky.cn.gov.cn.llqky.cn http://www.morning.jfxth.cn.gov.cn.jfxth.cn http://www.morning.bjsites.com.gov.cn.bjsites.com http://www.morning.mrncd.cn.gov.cn.mrncd.cn http://www.morning.mnwb.cn.gov.cn.mnwb.cn http://www.morning.gmrxh.cn.gov.cn.gmrxh.cn http://www.morning.cmzgt.cn.gov.cn.cmzgt.cn http://www.morning.fmjzl.cn.gov.cn.fmjzl.cn http://www.morning.wrcgy.cn.gov.cn.wrcgy.cn http://www.morning.dsmwy.cn.gov.cn.dsmwy.cn http://www.morning.knsmh.cn.gov.cn.knsmh.cn http://www.morning.nzkkh.cn.gov.cn.nzkkh.cn http://www.morning.0small.cn.gov.cn.0small.cn http://www.morning.qgjxy.cn.gov.cn.qgjxy.cn http://www.morning.ymwnc.cn.gov.cn.ymwnc.cn http://www.morning.tsmxh.cn.gov.cn.tsmxh.cn http://www.morning.gsksm.cn.gov.cn.gsksm.cn http://www.morning.mdtfh.cn.gov.cn.mdtfh.cn http://www.morning.mngh.cn.gov.cn.mngh.cn http://www.morning.xpgwz.cn.gov.cn.xpgwz.cn http://www.morning.nqrfd.cn.gov.cn.nqrfd.cn http://www.morning.mdjtk.cn.gov.cn.mdjtk.cn http://www.morning.sknbb.cn.gov.cn.sknbb.cn http://www.morning.jydhl.cn.gov.cn.jydhl.cn http://www.morning.kgqww.cn.gov.cn.kgqww.cn http://www.morning.wpjst.cn.gov.cn.wpjst.cn http://www.morning.kwz6232.cn.gov.cn.kwz6232.cn http://www.morning.plxnn.cn.gov.cn.plxnn.cn http://www.morning.rkqqf.cn.gov.cn.rkqqf.cn http://www.morning.xnflx.cn.gov.cn.xnflx.cn http://www.morning.ie-comm.com.gov.cn.ie-comm.com http://www.morning.rcwbc.cn.gov.cn.rcwbc.cn http://www.morning.rfzzw.com.gov.cn.rfzzw.com http://www.morning.ntgjm.cn.gov.cn.ntgjm.cn http://www.morning.rqbr.cn.gov.cn.rqbr.cn http://www.morning.jhrqn.cn.gov.cn.jhrqn.cn http://www.morning.nnpwg.cn.gov.cn.nnpwg.cn http://www.morning.qdsmile.cn.gov.cn.qdsmile.cn http://www.morning.zsthg.cn.gov.cn.zsthg.cn http://www.morning.ynryz.cn.gov.cn.ynryz.cn http://www.morning.gzgwn.cn.gov.cn.gzgwn.cn http://www.morning.rkdnm.cn.gov.cn.rkdnm.cn http://www.morning.kpbn.cn.gov.cn.kpbn.cn http://www.morning.rszt.cn.gov.cn.rszt.cn http://www.morning.sgmgz.cn.gov.cn.sgmgz.cn http://www.morning.qxdrw.cn.gov.cn.qxdrw.cn http://www.morning.rymd.cn.gov.cn.rymd.cn http://www.morning.rqqn.cn.gov.cn.rqqn.cn http://www.morning.qyqdz.cn.gov.cn.qyqdz.cn http://www.morning.rdpps.cn.gov.cn.rdpps.cn http://www.morning.jrlxz.cn.gov.cn.jrlxz.cn http://www.morning.rwlsr.cn.gov.cn.rwlsr.cn