从战中反弹:将Git提交信息作为JSON返回

在某些情况下,我们必须知道部署到远程服务器的Web应用程序的确切版本。 例如,客户可能想知道我们是否已经在服务器X上部署了错误修复程序。

当然,我们可以尝试使用“传统”方法找到该问题的答案。 问题是:

  • 没有人不记得是谁更新了服务器X或何时更新了服务器X。
  • 更新它的人不记得哪个是构建中包含的最后一次提交。

换句话说,我们被搞砸了。 我们可以尝试测试服务器X上是否仍然存在该错误,但这并不能真正帮助我们,因为我们的错误修复可能无法正常工作。

这篇博客文章描述了我们如何解决这个问题。 让我们从提取Git存储库的构建时状态开始。

如果使用Spring Boot,则应使用Spring Boot Actuator 。 它可以帮助您发布有关Git存储库状态的信息 。

如果您尚未阅读以下博客文章, 则应先阅读它们,然后再继续阅读此博客文章

  • 从槽中弹起:将属性值注入配置Bean描述了为什么应将属性值注入配置Bean并帮助您做到这一点。
  • 从槽中弹跳:以JSON返回运行时配置描述了如何将Web应用程序的运行时配置写入日志文件并将其作为JSON返回。

提取我们的Git仓库的构建时间状态

我们可以使用Maven Git Commit Id插件提取Git存储库的构建时状态。 让我们了解如何配置Maven Git Commit Id插件并将提取的信息添加到属性文件中。

首先 ,我们需要配置资源目录的位置,并确保将从属性文件中找到的属性占位符替换为实际的属性值。 为此,我们可以将以下XML添加到pom.xml文件的build部分中:

<resources><resource><directory>src/main/resources</directory><filtering>true</filtering><includes><include>**/*.properties</include></includes></resource>
</resources>

其次 ,我们需要配置Maven Git Commit Id插件。 我们可以按照以下步骤进行操作:

  1. 将Maven Git提交ID插件添加到我们的构建中。
  2. 确保在默认生命周期的初始化阶段调用了Maven Git Commit Id插件的修订目标。
  3. 配置.git目录的位置。

我们需要将以下XML添加到pom.xml文件的plugins部分:

<plugin><groupId>pl.project13.maven</groupId><artifactId>git-commit-id-plugin</artifactId><version>2.1.13</version><!--Ensure that the revision goal is invoked during the initializephase.--><executions><execution><goals><goal>revision</goal></goals></execution></executions><configuration><!--Configure the location of the .git directory.--><dotGitDirectory>${project.basedir}/../.git</dotGitDirectory></configuration>
</plugin>

如果您对Maven Git Commit Id插件的默认配置不满意,则应仔细阅读其自述文件:

  • 使用该插件提供了带注释的XML配置文件,该文件描述了Maven Git Commit Id插件的配置。
  • 深入的配置选项描述了Maven Git Commit Id插件的每个配置选项。

第三 ,我们需要创建属性文件,其中包含从Git存储库中提取的信息。 application.properties文件如下所示:

git.tags=${git.tags}
git.branch=${git.branch}
git.dirty=${git.dirty}
git.remote.origin.url=${git.remote.origin.url}git.commit.id=${git.commit.id}
git.commit.id.abbrev=${git.commit.id.abbrev}
git.commit.id.describe=${git.commit.id.describe}
git.commit.id.describe-short=${git.commit.id.describe-short}
git.commit.user.name=${git.commit.user.name}
git.commit.user.email=${git.commit.user.email}
git.commit.message.full=${git.commit.message.full}
git.commit.message.short=${git.commit.message.short}
git.commit.time=${git.commit.time}git.build.user.name=${git.build.user.name}
git.build.user.email=${git.build.user.email}
git.build.time=${git.build.time}

现在,我们已经配置了Maven Git Commit Id插件。 编译项目时,将从application.properties文件中找到的属性占位符替换为从Git存储库中提取的实际属性值。

target / classes目录中找到的application.properties文件如下所示:

git.tags=
git.branch=master
git.dirty=true
git.remote.origin.url=git@github.com:pkainulainen/spring-from-the-trenches.gitgit.commit.id=1bdfe9cf22b550a3ebe170f60df165e5c26448f9
git.commit.id.abbrev=1bdfe9c
git.commit.id.describe=1bdfe9c-dirty
git.commit.id.describe-short=1bdfe9c-dirty
git.commit.user.name=Petri Kainulainen
git.commit.user.email=petri.kainulainen@gmail.com
git.commit.message.full=Declare PropertySourcesPlaceholderConfigurer in a static @Bean method
git.commit.message.short=Declare PropertySourcesPlaceholderConfigurer in a static @Bean method
git.commit.time=16.04.2015 @ 23:35:23 EESTgit.build.user.name=Petri Kainulainen
git.build.user.email=petri.kainulainen@gmail.com
git.build.time=18.04.2015 @ 17:07:55 EEST

如果您不想创建属性文件,则Maven Git Commit Id插件可以为您生成一个 。

让我们继续前进,找出如何将Git提交信息注入到属性bean中。

将Git提交信息注入到属性Bean中

我们需要创建以下描述的三个属性bean类:

  • BuildProperties类包含有关开始构建的人的信息。
  • CommitProperties类包含有关构建中包含的最新提交的信息。
  • GitProperties类包含一些“公共”属性,例如branchtagsremoteOriginUrl 。 它还包含对BuildPropertiesCommitProperties对象的引用。

属性Bean与中描述的配置Bean相似
我以前的博客文章 。 我为这些类使用不同的后缀的原因是,它们不是Web应用程序配置的一部分。 它们仅包含写入日志文件并以JSON返回的信息。

另外,如果您不知道为什么要将属性值注入特殊的bean类中以及如何将其值注入,则应阅读我的博客文章,该文章回答了这两个问题 。

首先 ,我们需要创建BuildProperties类。 此类具有final timeuserEmailuserName字段。 通过使用构造函数注入将实际字段值注入到这些字段中。 BuildProperties类的源代码如下所示:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class BuildProperties {private final String time;private final String userEmail;private final String userName;@Autowiredpublic BuildProperties(@Value("${git.build.time}") String time,@Value("${git.build.user.email}") String userEmail,@Value("${git.build.user.name}") String userName) {this.time = time;this.userEmail = userEmail;this.userName = userName;}//Getters are omitted for the sake of clarity
}

其次 ,我们需要创建CommitProperties类。 该类具有最后的describedescribeShortfullMessageididAbbrevshortMessagetimeuserEmailuserName字段。 通过使用构造函数注入将实际属性值注入到这些字段中。 CommitProperties类的源代码如下所示:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class CommitProperties {private final String describe;private final String describeShort;private final String fullMessage;private final String id;private final String idAbbrev;private final String shortMessage;private final String time;private final String userEmail;private final String userName;@Autowiredpublic CommitProperties(@Value("${git.commit.id.describe}") String describe,@Value("${git.commit.id.describe-short}") String describeShort,@Value("${git.commit.message.full}") String fullMessage,@Value("${git.commit.id}") String id,@Value("${git.commit.id.abbrev}") String idAbbrev,@Value("${git.commit.message.short}") String shortMessage,@Value("${git.commit.time}") String time,@Value("${git.commit.user.email}") String userEmail,@Value("${git.commit.user.name}") String userName) {this.describe = describe;this.describeShort = describeShort;this.fullMessage = fullMessage;this.id = id;this.idAbbrev = idAbbrev;this.shortMessage = shortMessage;this.time = time;this.userEmail = userEmail;this.userName = userName;}//Getters are omitted for the sake of clarity
}

第三 ,我们需要创建GitProperties类。 此类具有最后的branchbuildcommitdirtyremoteOriginUrltags字段。 通过使用构造函数注入将实际字段值(或对象)注入这些字段。 GitProperties类的源代码如下所示:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class GitProperties {private String branch;private final BuildProperties build;private final CommitProperties commit;private final boolean dirty;private final String remoteOriginUrl;private final String tags;@Autowiredpublic GitProperties(@Value("${git.branch}") String branch,BuildProperties build,CommitProperties commit,@Value("${git.dirty}") boolean dirty,@Value("${git.remote.origin.url}") String remoteOriginUrl,@Value("${git.tags}") String tags) {this.branch = branch;this.build = build;this.commit = commit;this.dirty = dirty;this.remoteOriginUrl = remoteOriginUrl;this.tags = tags;}//Getters are omitted for the sake of clarity
}

让我们继续并将Git提交信息写入日志文件。

将Git提交信息写入日志文件

我们的下一步是将Git提交信息信息写入日志文件。 让我们找出如何做到这一点。

首先 ,我们必须向BuildPropertiesCommitPropertiesGitProperties类添加toString()方法,并使用ToStringBuilder类实现这些方法。

BuildProperties类的源代码如下所示:

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class BuildProperties {private final String time;private final String userEmail;private final String userName;@Autowiredpublic BuildProperties(@Value("${git.build.time}") String time,@Value("${git.build.user.email}") String userEmail,@Value("${git.build.user.name}") String userName) {this.time = time;this.userEmail = userEmail;this.userName = userName;}//Getters are omitted for the sake of clarity@Overridepublic String toString() {return new ToStringBuilder(this).append("time", this.time).append("userEmail", this.userEmail).append("userName", this.userName).toString();}
}

CommitProperties类的源代码如下所示:

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class CommitProperties {private final String describe;private final String describeShort;private final String fullMessage;private final String id;private final String idAbbrev;private final String shortMessage;private final String time;private final String userEmail;private final String userName;@Autowiredpublic CommitProperties(@Value("${git.commit.id.describe}") String describe,@Value("${git.commit.id.describe-short}") String describeShort,@Value("${git.commit.message.full}") String fullMessage,@Value("${git.commit.id}") String id,@Value("${git.commit.id.abbrev}") String idAbbrev,@Value("${git.commit.message.short}") String shortMessage,@Value("${git.commit.time}") String time,@Value("${git.commit.user.email}") String userEmail,@Value("${git.commit.user.name}") String userName) {this.describe = describe;this.describeShort = describeShort;this.fullMessage = fullMessage;this.id = id;this.idAbbrev = idAbbrev;this.shortMessage = shortMessage;this.time = time;this.userEmail = userEmail;this.userName = userName;}//Getters are omitted for the sake of clarity@Overridepublic String toString() {return new ToStringBuilder(this).append("describe", this.describe).append("describeShort", this.describeShort).append("fullMessage", this.fullMessage).append("id", this.id).append("idAbbrev", this.idAbbrev).append("shortMessage", this.shortMessage).append("time", this.time).append("userEmail", this.userEmail).append("userName", this.userName).toString();}
}

GitProperties类的源代码如下所示:

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class GitProperties {private String branch;private final BuildProperties build;private final CommitProperties commit;private final boolean dirty;private final String remoteOriginUrl;private final String tags;@Autowiredpublic GitProperties(@Value("${git.branch}") String branch,BuildProperties build,CommitProperties commit,@Value("${git.dirty}") boolean dirty,@Value("${git.remote.origin.url}") String remoteOriginUrl,@Value("${git.tags}") String tags) {this.branch = branch;this.build = build;this.commit = commit;this.dirty = dirty;this.remoteOriginUrl = remoteOriginUrl;this.tags = tags;}//Getters are omitted for the sake of clarity@Overridepublic String toString() {return new ToStringBuilder(this).append("branch", this.branch).append("build", this.build).append("commit", this.commit).append("dirty", this.dirty).append("remoteOriginUrl", this.remoteOriginUrl).append("tags", this.tags).toString();}
}

其次 ,我们必须在启动应用程序时将Git提交信息写入日志文件。 我们可以按照以下步骤进行操作:

  1. 静态的最终Logger字段添加到GitProperties类,并使用LoggerFactory类创建一个新的Logger对象。
  2. writeGitCommitInformationToLog()方法添加到GitProperties类,并使用@PostConstruct批注对其进行批注。 这样可以确保Spring容器在将创建的bean对象的依赖项注入到其中之后调用此方法。
  3. 通过将Git提交信息写入日志文件来实现writeGitCommitInformationToLog()方法。

完成这些更改后, GitProperties类的源代码如下所示:

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;@Component
public class GitProperties {private static final Logger LOGGER = LoggerFactory.getLogger(GitProperties.class);private String branch;private final BuildProperties build;private final CommitProperties commit;private final boolean dirty;private final String remoteOriginUrl;private final String tags;@Autowiredpublic GitProperties(@Value("${git.branch}") String branch,BuildProperties build,CommitProperties commit,@Value("${git.dirty}") boolean dirty,@Value("${git.remote.origin.url}") String remoteOriginUrl,@Value("${git.tags}") String tags) {this.branch = branch;this.build = build;this.commit = commit;this.dirty = dirty;this.remoteOriginUrl = remoteOriginUrl;this.tags = tags;}//Getters are omitted for the sake of clarity@Overridepublic String toString() {return new ToStringBuilder(this).append("branch", this.branch).append("build", this.build).append("commit", this.commit).append("dirty", this.dirty).append("remoteOriginUrl", this.remoteOriginUrl).append("tags", this.tags).toString();}@PostConstructpublic void writeGitCommitInformationToLog() {LOGGER.info("Application was built by using the Git commit: {}", this);}
}

启动Web应用程序时,应从其日志文件中找到以下信息:

INFO  - GitProperties - Application was built by using the Git commit: net.petrikainulainen.spring.trenches.config.GitProperties@47044f7d[branch=master,build=net.petrikainulainen.spring.trenches.config.BuildProperties@7b14c61[time=19.04.2015 @ 00:47:37 EEST,userEmail=petri.kainulainen@gmail.com,userName=Petri Kainulainen],commit=net.petrikainulainen.spring.trenches.config.CommitProperties@8fcc534[describe=1bdfe9c-dirty,describeShort=1bdfe9c-dirty,fullMessage=Declare PropertySourcesPlaceholderConfigurer in a static @Bean method,id=1bdfe9cf22b550a3ebe170f60df165e5c26448f9,idAbbrev=1bdfe9c,shortMessage=Declare PropertySourcesPlaceholderConfigurer in a static @Bean method,time=16.04.2015 @ 23:35:23 EEST,userEmail=petri.kainulainen@gmail.com,userName=Petri Kainulainen],dirty=true,remoteOriginUrl=git@github.com:pkainulainen/spring-from-the-trenches.git,tags=
]

该信息写在一行中,但是我对其进行了格式化,因为我想使其更易于阅读。

让我们了解如何将Git提交信息作为JSON返回。

以JSON形式返回Git提交信息

之前,我们创建了一个控制器类 , 该类将Web应用程序的运行时配置作为JSON返回。 让我们修改此类以将Git提交信息返回为JSON。 我们可以按照以下步骤进行操作:

  1. 最后的GitProperties字段添加到PropertiesController类。
  2. 通过使用构造函数注入将GitProperties bean注入到创建的控制器bean中。
  3. 创建一个控制器方法来处理发送到url'/ version'的GET请求,并通过返回GitProperties对象来实现它。

PropertiesController的源代码如下所示:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;@RestController
final class PropertiesController {private final ApplicationProperties applicationProperties;private final GitProperties gitProperties;@AutowiredPropertiesController(ApplicationProperties applicationProperties, GitProperties gitProperties) {this.applicationProperties = applicationProperties;this.gitProperties = gitProperties;}@RequestMapping(value = "/config", method = RequestMethod.GET)ApplicationProperties getAppConfiguration() {return applicationProperties;}@RequestMapping(value = "/version", method = RequestMethod.GET)GitProperties getVersion() {return gitProperties;}
}

当我们将GET请求发送到url'/ version'时,我们的控制器方法将返回以下JSON:

{"branch":"master","build":{"time":"19.04.2015 @ 00:47:37 EEST","userEmail":"petri.kainulainen@gmail.com","userName":"Petri Kainulainen"},"commit":{"describe":"1bdfe9c-dirty","describeShort":"1bdfe9c-dirty","fullMessage":"Declare PropertySourcesPlaceholderConfigurer in a static @Bean method","id":"1bdfe9cf22b550a3ebe170f60df165e5c26448f9","idAbbrev":"1bdfe9c","shortMessage":"Declare PropertySourcesPlaceholderConfigurer in a static @Bean method","time":"16.04.2015 @ 23:35:23 EEST","userEmail":"petri.kainulainen@gmail.com","userName":"Petri Kainulainen"},"dirty":true,"remoteOriginUrl":"git@github.com:pkainulainen/spring-from-the-trenches.git","tags":""
}

我们不应该允许所有人访问我们应用程序的Git提交信息。 如果这将是一个真实的应用程序,则应确保只有管理员才能访问此信息。

让我们继续并总结从这篇博客文章中学到的知识。

摘要

这篇博客文章教会了我们三件事:

  • 我们可以使用Maven Git Commit Id插件从Git存储库中提取构建时状态。
  • 我们可以通过重写属性bean类的toString()方法并将这些bean的属性值注入到日志文件中后,将Git提交信息写入日志文件。
  • 我们可以通过创建一个返回“根”属性bean对象( GitProperties )的控制器方法来将Git提交信息作为JSON返回。
  • PS:您可以从Github获得此博客文章的示例应用程序 。

翻译自: https://www.javacodegeeks.com/2015/04/spring-from-the-trenches-returning-git-commit-information-as-json.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/360174.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

在论坛中出现的各种疑难问题:日志收缩问题

最近&#xff0c;在论坛中&#xff0c;遇到了不少疑难的问题&#xff0c;在此特别记录&#xff0c;同时也感谢发帖人的分享、以及其他网友的热心回答。 1、日志暴大&#xff0c;无法收缩&#xff0c;谁来挑战一下&#xff01; http://bbs.csdn.net/topics/390674731?page1#pos…

学java前要学css_教你一招:学习Java必须学会的CSS用法

一&#xff1a;CSS概述什么是CSSCSS就是层叠样式表(Casading Style Sheets)&#xff0c;通常称为CSS样式表&#xff0c;或者是级联样式表。主要用于设置HTML中的文本&#xff0c;内容(字体&#xff0c;大小&#xff0c;对齐)&#xff0c;图片外形(宽高&#xff0c;边框样式&…

标准I/O库之缓冲

标准I/O库提供缓冲的目的是尽可能减少使用read和write调用的次数。它也对每个I/O流自动地进行缓冲管理&#xff0c;从而避免了应用程序需要考虑这一点所带来的麻烦。 标准I/O提供了三种类型的缓冲&#xff1a; &#xff08;1&#xff09;全缓冲。这种情况下&#xff0c;在填满标…

java如何写安卓接口文档_android、java制作sdk以及自动生成文档

最近一直在做android开发&#xff0c;昨天经理让我写个接口SDK做个接口文档&#xff0c;以便后面的开发。这让我很焦灼&#xff0c;SDK怎么做&#xff1f;要是只有敲代码还好。可是那个接口文档&#xff01;&#xff01;&#xff01;文档这东西最讨厌了&#xff0c;头都大了后来…

[转载]jquery cookie的用法

原文地址:http://www.cnblogs.com/qiantuwuliang/archive/2009/07/19/1526663.html jQuery cookie是个很好的cookie插件&#xff0c;大概的使用方法如下 example $.cookie(’name’, ‘value’); 设置cookie的值&#xff0c;把name变量的值设为value example $.cookie(’name’…

21世纪的设计模式:抽象工厂模式

这是我的演讲的第二部分&#xff0c;“ 21世纪的设计模式” 。 此模式在Java代码中到处都有使用&#xff0c;尤其是在更多“企业”代码库中。 它涉及一个接口和一个实现。 该界面如下所示&#xff1a; public interface Bakery {Pastry bakePastry(Topping topping);Cake bak…

java textfield类方法_java.awt.TextField类

java.awt.TextField是一个文本框组件1.构造方法TextField()&#xff1a;创建一个默认长度为一个机器字符长的文本框TextField(int n)&#xff1a;创建一个指定长度为n个机器字符长的文本框TextField(String s)&#xff1a;创建一个文本框&#xff0c;该文本框的初始字符串为sTe…

广东金融学院java实验报告_《大学计算机Ⅰ》实验报告实验三

广东金融学院实验报告课程名称&#xff1a;大学计算机Ⅰ实验编号 及实验名称 姓 名 实验地点 指导教师蔡文璇 12-204课室 伍春晖博士实验三 中文Excel 2007实验系 别 班 级 实验时数 成 绩财经传媒系 经济秘书(2)班6学 号 实验日期 同组其他成员111602242 2011年 12 月07 日无一…

Markdown会干掉Html吗?

Markdown会干掉Html吗&#xff1f; 很明显&#xff0c;MarkDown正在已一种比病毒还快的速度传播着&#xff0c;量子的机器人语言也是深受其启发&#xff0c;当然了&#xff0c;在这个东西没搞出来之前&#xff0c;MarkDown就能干很多事情&#xff0c;比如在线编辑。 有了它&…

java动态变量名反射_Java动态性—反射 - Eclipse666的个人空间 - OSCHINA - 中文开源技术交流社区...

1.什么是动态语言&#xff1f;程序运行时&#xff0c;可以改变程序的结构或者变量类型&#xff1b;如Python&#xff0c;javaScriptfunction(){var s"var a3;var b4;" evals(s);}在执行javascript代码的的过程中&#xff0c;可以改变变量的值或插入语句改变结构。但J…

java中的module是什么意思_Angular - 组件中module.id的含义是什么?

Update for (2017-03-13) &#xff1a;删除了所有提及的moduleId . “组件相对路径”cookbook已删除我们在我们推荐的SystemJS配置中添加了一个新的SystemJS插件(systemjs-angular-loader.js) . 此插件动态地将templateUrl和styleUrls中的“组件相对”路径转换为“绝对路径” .…

HTML跳转

Window.location.href"http://www.baidu.com/"转载于:https://www.cnblogs.com/hucaihao/p/3514165.html

Spring注释,我从来没有机会使用第1部分:@primary

今天&#xff0c;我想起了我的一个老朋友&#xff08;primary&#xff09;&#xff0c;我们从教程到教程都遇到了他。 您知道在Spring Autowired批注中按类型工作&#xff0c;也就是说&#xff0c;如果Spring找到符合类型的匹配的合格bean&#xff0c;则会将其注入。让我们在示…

mysql构建栋_【转载】这次拆库 应是微服务化的拆分方式

一、现状现状.png我们将一个大而全的系统一拆为三&#xff0c;容器&#xff0c;发布&#xff0c;测试都已经独立出去&#xff0c;但是原始的数据库还是一套&#xff0c;现在需要将数据库做一个拆分&#xff0c;A、B、C三个系统有各自的数据库之后&#xff0c;我们的微服务化在现…

使用SharePoint 2010新增的文档集内容类型来管理文档

使用SharePoint 2010新增的文档集内容类型来管理文档 SharePoint 2010新增加的文档集功能是作为内容类型存在的&#xff0c;使用范围在网站集中&#xff0c;需要激活“文档集”功能到网站集才可以正常使用。文档集其实就是一个SharePoint产品增强的文件夹和内容类型的综合体现。…

如何使用Java 8流快速替换列表中的元素

假设您有一个项目清单&#xff1a; List<String> books Arrays.asList("The Holy Cow: The Bovine Testament","True Hip Hop","Truth and Existence","The Big Book of Green Design" );&#xff08;不要判断我。此随机书生成…

db2和mysql性能优化_DB2数据库性能调优的十个办法

这篇文章主要是针对e-business OLTP的10个性能方面的Tips。10. Monitor Switches打开Monitor Switch,才能获得性能方面的信息,命令如下db2 "update monitor switches using lock ON sort ON bufferpool ON uow ON table ON statement ON"9. Agents要保证有足够的agen…

处理远程通知的方法

IOS的一大特点就是可以随时向客户端push相关的信息。那么在客户端收到这些信息时&#xff0c;如何处理呢&#xff1f; 有两种情景需要处理&#xff0c; 一是&#xff1a;从状态栏下拉&#xff0c;点击通知栏里的一项&#xff0c;启动应用 二是&#xff1a;在锁屏界面&#xff0…

java merge into_Oracle merge into的使用

最近项目上使用Oracle的Merge&#xff0c;所以找来一下资料学习了解。该命令使用一条语句从一个或者多个数据源中完成对表的更新和插入数据. ORACLE 9i 中&#xff0c;使用此命令必须同时指定UPDATE 和INSERT 关键词,ORACLE 10g 做了如下改动。特点&#xff1a;1、insert 和upd…

基于visual Studio2013解决算法导论之019栈实现(基于数组)

&#xfeff;&#xfeff;&#xfeff;题目用数组实现栈解决代码及点评#include <stdio.h> #include <stdlib.h> #include <time.h> #include <malloc.h> #include<assert.h>typedef struct Stack {int nTop;int nLen;int *pnArr; }Stack, *PSta…