properties

PHP copy all object properties to this

≯℡__Kan透↙ 提交于 2020-04-07 14:46:45
问题 I have an object in PHP, of the type MyObject . $myObject instanceof MyObject Now, in the class MyObject , there is a non-static function, and in there, I use the reference to "me", like $this , but I also have another object there. Is it possible, without doing $this = $myObject , to achieve more or less the same effect, like something of the sort set_object_vars($this, get_object_vars($myObject)) ? 回答1: <?php class MyObject { public function import(MyObject $object) { foreach (get_object

PHP copy all object properties to this

不打扰是莪最后的温柔 提交于 2020-04-07 14:46:27
问题 I have an object in PHP, of the type MyObject . $myObject instanceof MyObject Now, in the class MyObject , there is a non-static function, and in there, I use the reference to "me", like $this , but I also have another object there. Is it possible, without doing $this = $myObject , to achieve more or less the same effect, like something of the sort set_object_vars($this, get_object_vars($myObject)) ? 回答1: <?php class MyObject { public function import(MyObject $object) { foreach (get_object

在SpringBoot下读取自定义properties配置文件的方法

白昼怎懂夜的黑 提交于 2020-04-07 10:13:31
SpringBoot工程默认读取application.properties配置文件。如果需要自定义properties文件,如何读取呢? 一、在resource中新建.properties文件 在resource目录下新建一个config文件夹,然后新建一个.properties文件放在该文件夹下。如图remote.properties所示 二、编写配置文件 1 2 remote.uploadFilesUrl=/resource/files/ remote.uploadPicUrl=/resource/pic/ 三、新建一个配置类RemoteProperties.java 1 2 3 4 5 6 7 8 9 @Configuration @ConfigurationProperties (prefix = "remote" , ignoreUnknownFields = false ) @PropertySource ( "classpath:config/remote.properties" ) @Data @Component public class RemoteProperties { private String uploadFilesUrl; private String uploadPicUrl; } 其中 @Configuration 表明这是一个配置类

java 反射实现框架功能

*爱你&永不变心* 提交于 2020-04-06 08:45:46
框架与框架要解决的核心问题 我做房子卖给用户住,由用户自己安装门窗和空调,我做的房子就是框架,用户需要使用我的框架,把门窗插入进我提供的框架中。框架与工具类有区别,工具类被用户的类调用,而框架则是调用用户提供的类。 框架要解决的核心问题 我在写框架(房子)时,你这个用户可能还在上小学,还不会写程序呢?我写的框架程序怎样能调用到你以后写的类(门窗)呢? 因为在写才程序时无法知道要被调用的类名,所以,在程序中无法直接new 某个类的实例对象了,而要用反射方式来做。 综合案例 先直接用new语句创建ArrayList和HashSet的实例对象,演示用eclipse自动生成 ReflectPoint类的equals和hashcode方法,比较两个集合的运行结果差异。 然后改为采用配置文件加反射的方式创建ArrayList和HashSet的实例对象,比较观察运行结果差异。 引入了elipse对资源文件的管理方式的讲解。 Eg: package july78javaEnhance; //利用资源文件加上反射操作! import java.io.FileInputStream ; import java.io.InputStream; import java.util.Collection; import java.util.Properties; public class

用Ant构建脚本(2)

让人想犯罪 __ 提交于 2020-04-05 20:54:51
用Ant构建脚本(2) 二、用Ant写buildfile Ant的buildfile是用xml写的。每一个buildfile包含了一个项目和一个及一个以上的对象。对象包含了多个任务元素。buildfile的每一个任务元素能有一个id属性,能在之后通过值来引用。这个值是唯一的。 build.xml文件是区分大小写的。其使用关键是编写build.xml文件,build.xml文件有五个主要的标识,如下: 1、Project元素 定义项目的属性,该标识有三个可以选择的属性: Name项目的名称; Default默认执行的target对象; Basedir用于计算所有其它路径的基本路径(“.”表示当前路径)。该属性可以被basedir property覆盖,当覆盖时,该属性会被忽略。 示例: <project name="examples" default="all" basedir="."> 2、Target元素 定义Ant命令的编译对象。 如Ant converter的编译对象是<target name="converter"> Target标识的属性解释如下: Name,定义target的名字,供Ant命令使用; Depends,定义它所依赖的其它执行对象,多个时用“,”隔开,即依赖表; If,条件执行,执行target所需要设定的属性名,其property的值被设置后执行;

编写命令行工具

人盡茶涼 提交于 2020-04-04 03:25:26
1、使用 common-cli 编写命令行工具 commons-cli 是Apache开源组织提供的用于解析命令行参数的包。 先引用common-cli依赖包: <groupId>commons-cli</groupId><artifactId>commons-cli</artifactId><version>1.2</version> 命令定义: private static final Options OPTIONS = new Options(); public void defineCommand() { OPTIONS.addOption("i", true, "the input directory where the proto files are"); OPTIONS.addOption("o", true, "the output directory which is the output path"); OPTIONS.addOption("c",true,"whether we use config.json or not"); OPTIONS.addOption("groupId",true,"maven project related parameter"); OPTIONS.addOption("artifactId",true,"maven

Android Sutido 编译速度优化

浪尽此生 提交于 2020-04-03 05:46:59
虽然 Android Studio 此时已经更新到了Android Studio 2.1版本,build 版本android-studio-bundle-143.2739321。但是在安装该版本都是根据自己的标准进行安装,所以需要在安装之后进行一系列的调整。下面文章根据3个方面进行讲解。分别为Android Studio本身、Gradle、不调整出现的编译上的问题。 Android Studio优化 编译优化需要有两个步骤,以下一一介绍。 步骤一:Gradle编译优化 在项目的根目录中进行修改。修改gradle.properties, gradle.properties 该文件的位置(H/gradle.properties) Project-wide Gradle settings. IDE (e.g. Android Studio) users: Gradle settings configured through the IDE will override any settings specified in this file. For more details on how to configure your build environment visit http://www.gradle.org/docs/current/userguide/build

Java读取src下配置文件的问题

*爱你&永不变心* 提交于 2020-03-31 10:23:38
博客原文: https://www.zjhuiwan.cn/info/20200331/4006622486333016.html 读取配置文件的几种方式: (1)通过当前类获得根目录的路径然后获取文件。可以在非Web应用中读取配置资源信息,可以读取任意的资源文件信息。 缺点:只能加载类src下面的资源文件,不适合装载大文件,否则会导致jvm内存溢出 InputStream fstream = this.getClass().getClassLoader().getResourceAsStream("config.properties"); //直接类调用TestController为当前类 “/”代表src目录下,不加则为该controller同包下 InputStream is = TestController.class.getResourceAsStream("/config.properties"); (2)可以以完全限定类名的方式加载资源后,直接的读取出来,且可以在非Web应用中读取资源文件。 缺点:该方式只能加载类src下面的资源文件且只能读取.properties文件。 // 获得资源包 ResourceBundle rb = ResourceBundle.getBundle("config.properties"); (3)使用Spring框架提供的

二、外部化配置--SpringBoot功能

∥☆過路亽.° 提交于 2020-03-30 18:52:07
一、外部化配置 Spring Boot将你的配置外部化,因此你可以在不同的环境下运行相同的代码。你可以使用 properties 文件, YAML 文件,环境变量,命令行参数在外部配置。使用@Value注解可以直接将属性值注入到bean中,通过Spring的 Environment 抽象访问,或通过 @ConfigurationProperties 绑定到结构化对象。 Spring Boot有多种外部配置方式,优先级如下: 当devtools开启时, $HOME/.config/spring-boot 下devtools的全局设置属性。 测试上的@TestPropertySource注解 测试中的 properties 属性。 在 @SpringBootTest 和测试注释上可用,用于测试应用程序的特定部分。 命令行参数 来自 SPRING_APPLICATION_JSON 的属性(嵌入在环境变量或系统属性中的内联JSON) ServletConfig 的初始参数. ServletContext 初始参数 来自 Java:comp / env 的JNDI属性。 Java系统属性( System.getProperties() ). 操作系统环境变量. RandomValuePropertySource 仅具有 random.* 属性. jar包外部的application-

Druid连接池的使用

江枫思渺然 提交于 2020-03-29 22:07:54
Druid简介 Druid是阿里开源的数据库连接池,作为后起之秀,性能比dbcp、c3p0更高,使用也越来越广泛。 druid的优点 高性能。性能比dbcp、c3p0高很多。 只要是jdbc支持的数据库,druid都支持,对数据库的支持性好。并且Druid针对oracle、mysql做了特别优化。 提供监控功能。可以监控sql语句的执行时间、ResultSet持有时间、返回行数、更新行数、错误次数、错误堆栈等信息,来了解连接池、sql语句的工作情况,方便统计、分析SQL的执行性能 Druid的使用 添加druid的依赖、数据库驱动 <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.8</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.19</version> </dependency> 纯代码方式     //数据源配置 DruidDataSource dataSource = new DruidDataSource(); dataSource.setUrl("jdbc