SpringApplication会从以下路径加载所有的application.properties文件:

  1. 1file:./config/(当前目录下的config文件夹)
  2. 2file:./(当前目录)
  3. 3classpath:/config/classpath下的config目录)
  4. 4classpath:/(classpath根目录)

优先级由上至下。
注意:优先级是指属性最后使用的值,而不是说仅仅扫描优先级高的路径,不是发现了application.properties文件就停止。例如classpath:/config/和file:./config/都存在配置文件,那么加载过程会加载classpath:/config/路径下配置文件的所有属性,然后再加载file:./config/路径下配置文件的属性并替换已有的属性。此外,如果你在相同优先级位置同时有application.properties和application.yml,那么application.yml里面的属性就会覆盖application.properties里的属性。
如果你不想使用application.properties的格式命名配置文件,那么可以通过环境变量spring.config.name来设置文件名称,例如:
$ java -jar myproject.jar --spring.config.name=example-sys.properties此时,要加载的配置文件名为example-sys.properties。除了修改名称,还可以使用 spring.config.location 来添加要加载的路径。例如我们以这个命令启动JVM:$ java -jar myapp.jar --spring.config.location=classpath:/myconfig/,file:./myconfig/
那么加载application.properties文件的路径以及优先级会变为:

  1. 1file:./myconfig/
  2. 2classpath:/myconfig/
  3. 3file:./config/
  4. 4file:./
  5. 5classpath:/config/
  6. 6classpath:/

spring.config.location环境变量也可以直接设定到加载文件的名称,例如:--spring.config.location=classpath:/default.properties
通常情况下这样做并没有太大问题,但是结合到Profiles文件特性时,会导致无法根据标记加载对应的Profiles文件。
由于配置文件路径和配置文件名称在容器未启动时就需要声明,所以最好在OS的环境变量、JVM的系统环境变量或命令行参数就设定它。

注:

"file:"文件路径前缀的相对路径根目录是 用户当前目录(即用户运行jar包时的当前目录)

"classpath:"文件路径前缀的相对路径根目录是 jar包内classes文件夹

  1. classpath 优先本项目class路径查找,没有的话依次在其他jar包中class路径查找,找到第一个匹配的为止
  2. classpath* 加载到所有class路径下的配置文件,包括jar包的class路径下,最终加载所有匹配的
  3. file 通过URL加载,来源为文件系统(注意文件读取权限)
  4. http 通过URL加载,来源为网络
  5. (none) 根据 ApplicationContext 进行判断(这个我没试过)

classpath

  1. <context:property-placeholder location="classpath:system.properties" />

举个栗子:A项目中resources中存在system.properties,B项目中resources中也存在system.properties。A项目以jar包形式引入B项目。此时A项目spring配置classpath:system.properties加载到的是A项目自己的system.properties。但是如果A项目resources中没有system.properties则最终结果加载到的是B.jar中的system.properties

classpath*

  1. <context:property-placeholder location="classpath*:system.properties" />

举个栗子:A项目中resources中存在system.properties,B项目中resources中也存在system.properties。A项目以jar包形式引入B项目。此时A项目spring配置classpath*:system.properties加载到的是A和B的system.properties
如下图(我是引入的两个jar都有同名配置文件):


这里大家可能会有疑问,同时引入了两个同名配置文件,如果两个同名配置文件中有同样的配置,比如:
A项目system.properties

  1. milo=a
  2. milo1=a

B项目system.properties

  1. milo=b
  2. milo1=b

那么最终引用的是哪个?我这边最终实验结果是根据spring加载顺序倒叙加载,直到找到匹配的值。而且值与值之间不影响,每次都按加载顺序倒叙查找。即:如果spring加载顺序为A->B ,那么最终取到的值为:milo=b milo1=b。而且spring在取milo和milo1时都是按照spring加载顺序倒叙取得。大家可以通过三个配置文件情况做下试验。对spring熟悉的同学也可找下源码看一下。

附:

application.properties参数详解

  1. # ----------------------------------------
  2. # CORE PROPERTIES
  3. # ----------------------------------------
  4.  
  5. # SPRING 相关配置 (ConfigFileApplicationListener)
  6. spring.config.name= # config file name (default to 'application')
  7. spring.config.location= # location of config file
  8.  
  9. # profile相关配置
  10. spring.profiles= # comma list of active profiles
  11.  
  12. # 系统配置相关参数 (SpringApplication)
  13. spring.main.sources=
  14. spring.main.web-environment= # detect by default
  15. spring.main.show-banner=true
  16. spring.main....= # see class for all properties
  17.  
  18. # 日志配置相关参数
  19. logging.path=/var/logs
  20. logging.file=myapp.log
  21. logging.config=
  22.  
  23. # IDENTITY (ContextIdApplicationContextInitializer)
  24. spring.application.name=
  25. spring.application.index=
  26.  
  27. # tomcat相关配置参数 (ServerProperties)
  28. server.port=8080
  29. server.address= # bind to a specific NIC
  30. server.session-timeout= # session timeout in seconds
  31. server.context-path= # the context path, defaults to '/'
  32. server.servlet-path= # the servlet path, defaults to '/'
  33. server.tomcat.access-log-pattern= # log pattern of the access log
  34. server.tomcat.access-log-enabled=false # is access logging enabled
  35. server.tomcat.protocol-header=x-forwarded-proto # ssl forward headers
  36. server.tomcat.remote-ip-header=x-forwarded-for
  37. server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp)
  38. server.tomcat.background-processor-delay=30; # in seconds
  39. server.tomcat.max-threads = 0 # number of threads in protocol handler
  40. server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding
  41.  
  42. # springmvc相关配置参数 (HttpMapperProperties)
  43. http.mappers.json-pretty-print=false # pretty print JSON
  44. http.mappers.json-sort-keys=false # sort keys
  45. spring.mvc.locale= # set fixed locale, e.g. en_UK
  46. spring.mvc.date-format= # set fixed date format, e.g. dd/MM/yyyy
  47. spring.mvc.message-codes-resolver-format= # PREFIX_ERROR_CODE / POSTFIX_ERROR_CODE
  48. spring.view.prefix= # MVC view prefix
  49. spring.view.suffix= # ... and suffix
  50. spring.resources.cache-period= # cache timeouts in headers sent to browser
  51. spring.resources.add-mappings=true # if default mappings should be added
  52.  
  53. # thymeleaf相关配置参数 (ThymeleafAutoConfiguration)
  54. spring.thymeleaf.prefix=classpath:/templates/
  55. spring.thymeleaf.suffix=.html
  56. spring.thymeleaf.mode=HTML5
  57. spring.thymeleaf.encoding=UTF-8
  58. spring.thymeleaf.content-type=text/html # ;charset=<encoding> is added
  59. spring.thymeleaf.cache=true # set to false for hot refresh
  60.  
  61. # freemark相关配置参数 (FreeMarkerAutoConfiguration)
  62. spring.freemarker.allowRequestOverride=false
  63. spring.freemarker.allowSessionOverride=false
  64. spring.freemarker.cache=true
  65. spring.freemarker.checkTemplateLocation=true
  66. spring.freemarker.contentType=text/html
  67. spring.freemarker.exposeRequestAttributes=false
  68. spring.freemarker.exposeSessionAttributes=false
  69. spring.freemarker.exposeSpringMacroHelpers=false
  70. spring.freemarker.prefix=
  71. spring.freemarker.requestContextAttribute=
  72. spring.freemarker.settings.*=
  73. spring.freemarker.suffix=.ftl
  74. spring.freemarker.templateEncoding=UTF-8
  75. spring.freemarker.templateLoaderPath=classpath:/templates/
  76. spring.freemarker.viewNames= # whitelist of view names that can be resolved
  77.  
  78. # groovy模板相关配置参数 (GroovyTemplateAutoConfiguration)
  79. spring.groovy.template.allowRequestOverride=false
  80. spring.groovy.template.allowSessionOverride=false
  81. spring.groovy.template.cache=true
  82. spring.groovy.template.configuration.*= # See Groovy's TemplateConfiguration
  83. spring.groovy.template.contentType=text/html
  84. spring.groovy.template.prefix=classpath:/templates/
  85. spring.groovy.template.suffix=.tpl
  86. spring.groovy.template.templateEncoding=UTF-8
  87. spring.groovy.template.viewNames= # whitelist of view names that can be resolved
  88.  
  89. # velocity模板相关配置参数 (VelocityAutoConfiguration)
  90. spring.velocity.allowRequestOverride=false
  91. spring.velocity.allowSessionOverride=false
  92. spring.velocity.cache=true
  93. spring.velocity.checkTemplateLocation=true
  94. spring.velocity.contentType=text/html
  95. spring.velocity.dateToolAttribute=
  96. spring.velocity.exposeRequestAttributes=false
  97. spring.velocity.exposeSessionAttributes=false
  98. spring.velocity.exposeSpringMacroHelpers=false
  99. spring.velocity.numberToolAttribute=
  100. spring.velocity.prefix=
  101. spring.velocity.properties.*=
  102. spring.velocity.requestContextAttribute=
  103. spring.velocity.resourceLoaderPath=classpath:/templates/
  104. spring.velocity.suffix=.vm
  105. spring.velocity.templateEncoding=UTF-8
  106. spring.velocity.viewNames= # whitelist of view names that can be resolved
  107.  
  108. # INTERNATIONALIZATION (MessageSourceAutoConfiguration)
  109. spring.messages.basename=messages
  110. spring.messages.cacheSeconds=-1
  111. spring.messages.encoding=UTF-8
  112.  
  113. # 安全相关配置参数 (SecurityProperties)
  114. security.user.name=user # login username
  115. security.user.password= # login password
  116. security.user.role=USER # role assigned to the user
  117. security.require-ssl=false # advanced settings ...
  118. security.enable-csrf=false
  119. security.basic.enabled=true
  120. security.basic.realm=Spring
  121. security.basic.path= # /**
  122. security.headers.xss=false
  123. security.headers.cache=false
  124. security.headers.frame=false
  125. security.headers.contentType=false
  126. security.headers.hsts=all # none / domain / all
  127. security.sessions=stateless # always / never / if_required / stateless
  128. security.ignored=false
  129.  
  130. # 数据源相关配置参数(DataSourceAutoConfiguration & DataSourceProperties)
  131. spring.datasource.name= # name of the data source
  132. spring.datasource.initialize=true # populate using data.sql
  133. spring.datasource.schema= # a schema (DDL) script resource reference
  134. spring.datasource.data= # a data (DML) script resource reference
  135. spring.datasource.platform= # the platform to use in the schema resource (schema-${platform}.sql)
  136. spring.datasource.continueOnError=false # continue even if can't be initialized
  137. spring.datasource.separator=; # statement separator in SQL initialization scripts
  138. spring.datasource.driverClassName= # JDBC Settings...
  139. spring.datasource.url=
  140. spring.datasource.username=
  141. spring.datasource.password=
  142. spring.datasource.max-active=100 # Advanced configuration...
  143. spring.datasource.max-idle=8
  144. spring.datasource.min-idle=8
  145. spring.datasource.initial-size=10
  146. spring.datasource.validation-query=
  147. spring.datasource.test-on-borrow=false
  148. spring.datasource.test-on-return=false
  149. spring.datasource.test-while-idle=
  150. spring.datasource.time-between-eviction-runs-millis=
  151. spring.datasource.min-evictable-idle-time-millis=
  152. spring.datasource.max-wait-millis=
  153.  
  154. # mongdb相关配置参数 (MongoProperties)
  155. spring.data.mongodb.host= # the db host
  156. spring.data.mongodb.port=27017 # the connection port (defaults to 27107)
  157. spring.data.mongodb.uri=mongodb://localhost/test # connection URL
  158. spring.data.mongo.repositories.enabled=true # if spring data repository support is enabled
  159.  
  160. # springDataJPA相关配置参数(JpaBaseConfiguration, HibernateJpaAutoConfiguration)
  161. spring.jpa.properties.*= # properties to set on the JPA connection
  162. spring.jpa.openInView=true
  163. spring.jpa.show-sql=true
  164. spring.jpa.database-platform=
  165. spring.jpa.database=
  166. spring.jpa.generate-ddl=false # ignored by Hibernate, might be useful for other vendors
  167. spring.jpa.hibernate.naming-strategy= # naming classname
  168. spring.jpa.hibernate.ddl-auto= # defaults to create-drop for embedded dbs
  169. spring.data.jpa.repositories.enabled=true # if spring data repository support is enabled
  170.  
  171. # solr相关配置参数(SolrProperties})
  172. spring.data.solr.host=http://127.0.0.1:8983/solr
  173. spring.data.solr.zkHost=
  174. spring.data.solr.repositories.enabled=true # if spring data repository support is enabled
  175.  
  176. # elasticsearch相关配置参数(ElasticsearchProperties})
  177. spring.data.elasticsearch.cluster-name= # The cluster name (defaults to elasticsearch)
  178. spring.data.elasticsearch.cluster-nodes= # The address(es) of the server node (comma-separated; if not specified starts a client node)
  179. spring.data.elasticsearch.local=true # if local mode should be used with client nodes
  180. spring.data.elasticsearch.repositories.enabled=true # if spring data repository support is enabled
  181.  
  182. # flyway相关配置参数(FlywayProperties)
  183. flyway.locations=classpath:db/migrations # locations of migrations scripts
  184. flyway.schemas= # schemas to update
  185. flyway.initVersion= 1 # version to start migration
  186. flyway.prefix=V
  187. flyway.suffix=.sql
  188. flyway.enabled=true
  189. flyway.url= # JDBC url if you want Flyway to create its own DataSource
  190. flyway.user= # JDBC username if you want Flyway to create its own DataSource
  191. flyway.password= # JDBC password if you want Flyway to create its own DataSource
  192.  
  193. # liquibase相关配置参数(LiquibaseProperties)
  194. liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml
  195. liquibase.contexts= # runtime contexts to use
  196. liquibase.default-schema= # default database schema to use
  197. liquibase.drop-first=false
  198. liquibase.enabled=true
  199.  
  200. # JMX
  201. spring.jmx.enabled=true # Expose MBeans from Spring
  202.  
  203. # rabbitmq相关配置参数(RabbitProperties)
  204. spring.rabbitmq.host= # connection host
  205. spring.rabbitmq.port= # connection port
  206. spring.rabbitmq.addresses= # connection addresses (e.g. myhost:9999,otherhost:1111)
  207. spring.rabbitmq.username= # login user
  208. spring.rabbitmq.password= # login password
  209. spring.rabbitmq.virtualhost=
  210. spring.rabbitmq.dynamic=
  211.  
  212. # redis相关配置参数(RedisProperties)
  213. spring.redis.host=localhost # server host
  214. spring.redis.password= # server password
  215. spring.redis.port=6379 # connection port
  216. spring.redis.pool.max-idle=8 # pool settings ...
  217. spring.redis.pool.min-idle=0
  218. spring.redis.pool.max-active=8
  219. spring.redis.pool.max-wait=-1
  220.  
  221. # activemq相关配置参数(ActiveMQProperties)
  222. spring.activemq.broker-url=tcp://localhost:61616 # connection URL
  223. spring.activemq.user=
  224. spring.activemq.password=
  225. spring.activemq.in-memory=true # broker kind to create if no broker-url is specified
  226. spring.activemq.pooled=false
  227.  
  228. # hornetq相关配置参数(HornetQProperties)
  229. spring.hornetq.mode= # connection mode (native, embedded)
  230. spring.hornetq.host=localhost # hornetQ host (native mode)
  231. spring.hornetq.port=5445 # hornetQ port (native mode)
  232. spring.hornetq.embedded.enabled=true # if the embedded server is enabled (needs hornetq-jms-server.jar)
  233. spring.hornetq.embedded.serverId= # auto-generated id of the embedded server (integer)
  234. spring.hornetq.embedded.persistent=false # message persistence
  235. spring.hornetq.embedded.data-directory= # location of data content (when persistence is enabled)
  236. spring.hornetq.embedded.queues= # comma separate queues to create on startup
  237. spring.hornetq.embedded.topics= # comma separate topics to create on startup
  238. spring.hornetq.embedded.cluster-password= # customer password (randomly generated by default)
  239.  
  240. # JMS (JmsProperties)
  241. spring.jms.pub-sub-domain= # false for queue (default), true for topic
  242.  
  243. # springbatch相关配置参数(BatchDatabaseInitializer)
  244. spring.batch.job.names=job1,job2
  245. spring.batch.job.enabled=true
  246. spring.batch.initializer.enabled=true
  247. spring.batch.schema= # batch schema to load
  248.  
  249. # aop相关配置参数
  250. spring.aop.auto=
  251. spring.aop.proxy-target-class=
  252.  
  253. # FILE ENCODING (FileEncodingApplicationListener)
  254. spring.mandatory-file-encoding=false
  255.  
  256. # SPRING SOCIAL (SocialWebAutoConfiguration)
  257. spring.social.auto-connection-views=true # Set to true for default connection views or false if you provide your own
  258.  
  259. # SPRING SOCIAL FACEBOOK (FacebookAutoConfiguration)
  260. spring.social.facebook.app-id= # your application's Facebook App ID
  261. spring.social.facebook.app-secret= # your application's Facebook App Secret
  262.  
  263. # SPRING SOCIAL LINKEDIN (LinkedInAutoConfiguration)
  264. spring.social.linkedin.app-id= # your application's LinkedIn App ID
  265. spring.social.linkedin.app-secret= # your application's LinkedIn App Secret
  266.  
  267. # SPRING SOCIAL TWITTER (TwitterAutoConfiguration)
  268. spring.social.twitter.app-id= # your application's Twitter App ID
  269. spring.social.twitter.app-secret= # your application's Twitter App Secret
  270.  
  271. # SPRING MOBILE SITE PREFERENCE (SitePreferenceAutoConfiguration)
  272. spring.mobile.sitepreference.enabled=true # enabled by default
  273.  
  274. # SPRING MOBILE DEVICE VIEWS (DeviceDelegatingViewResolverAutoConfiguration)
  275. spring.mobile.devicedelegatingviewresolver.enabled=true # disabled by default
  276. spring.mobile.devicedelegatingviewresolver.normalPrefix=
  277. spring.mobile.devicedelegatingviewresolver.normalSuffix=
  278. spring.mobile.devicedelegatingviewresolver.mobilePrefix=mobile/
  279. spring.mobile.devicedelegatingviewresolver.mobileSuffix=
  280. spring.mobile.devicedelegatingviewresolver.tabletPrefix=tablet/
  281. spring.mobile.devicedelegatingviewresolver.tabletSuffix=
  282.  
  283. # ----------------------------------------
  284. # ACTUATOR PROPERTIES
  285. # ----------------------------------------
  286.  
  287. # MANAGEMENT HTTP SERVER (ManagementServerProperties)
  288. management.port= # defaults to 'server.port'
  289. management.address= # bind to a specific NIC
  290. management.contextPath= # default to '/'
  291.  
  292. # ENDPOINTS (AbstractEndpoint subclasses)
  293. endpoints.autoconfig.id=autoconfig
  294. endpoints.autoconfig.sensitive=true
  295. endpoints.autoconfig.enabled=true
  296. endpoints.beans.id=beans
  297. endpoints.beans.sensitive=true
  298. endpoints.beans.enabled=true
  299. endpoints.configprops.id=configprops
  300. endpoints.configprops.sensitive=true
  301. endpoints.configprops.enabled=true
  302. endpoints.configprops.keys-to-sanitize=password,secret
  303. endpoints.dump.id=dump
  304. endpoints.dump.sensitive=true
  305. endpoints.dump.enabled=true
  306. endpoints.env.id=env
  307. endpoints.env.sensitive=true
  308. endpoints.env.enabled=true
  309. endpoints.health.id=health
  310. endpoints.health.sensitive=false
  311. endpoints.health.enabled=true
  312. endpoints.info.id=info
  313. endpoints.info.sensitive=false
  314. endpoints.info.enabled=true
  315. endpoints.metrics.id=metrics
  316. endpoints.metrics.sensitive=true
  317. endpoints.metrics.enabled=true
  318. endpoints.shutdown.id=shutdown
  319. endpoints.shutdown.sensitive=true
  320. endpoints.shutdown.enabled=false
  321. endpoints.trace.id=trace
  322. endpoints.trace.sensitive=true
  323. endpoints.trace.enabled=true
  324.  
  325. # MVC ONLY ENDPOINTS
  326. endpoints.jolokia.path=jolokia
  327. endpoints.jolokia.sensitive=true
  328. endpoints.jolokia.enabled=true # when using Jolokia
  329. endpoints.error.path=/error
  330.  
  331. # JMX ENDPOINT (EndpointMBeanExportProperties)
  332. endpoints.jmx.enabled=true
  333. endpoints.jmx.domain= # the JMX domain, defaults to 'org.springboot'
  334. endpoints.jmx.unique-names=false
  335. endpoints.jmx.enabled=true
  336. endpoints.jmx.staticNames=
  337.  
  338. # JOLOKIA (JolokiaProperties)
  339. jolokia.config.*= # See Jolokia manual
  340.  
  341. # REMOTE SHELL
  342. shell.auth=simple # jaas, key, simple, spring
  343. shell.command-refresh-interval=-1
  344. shell.command-path-pattern= # classpath*:/commands/**, classpath*:/crash/commands/**
  345. shell.config-path-patterns= # classpath*:/crash/*
  346. shell.disabled-plugins=false # don't expose plugins
  347. shell.ssh.enabled= # ssh settings ...
  348. shell.ssh.keyPath=
  349. shell.ssh.port=
  350. shell.telnet.enabled= # telnet settings ...
  351. shell.telnet.port=
  352. shell.auth.jaas.domain= # authentication settings ...
  353. shell.auth.key.path=
  354. shell.auth.simple.user.name=
  355. shell.auth.simple.user.password=
  356. shell.auth.spring.roles=
  357.  
  358. # GIT INFO
  359. spring.git.properties= # resource ref to generated git info properties file

参考文献:

SpringBoot配置文件application.properties参数详解

Spring Boot学习总结(13)——Spring Boot加载application.properties配置文件顺序规则

Spring Boot加载application.properties配置文件顺序规则的更多相关文章

  1. Spring Boot 加载application.properties顺序

    1.准备四份application.properties a.项目根目录下config/application.properties ,内容为:  test.user.name = a b.项目根目录 ...

  2. eclips环境下开发spring boot项目,application.properties配置文件下中文乱码解决方案

    如以上,application.properties文件下中文乱码.发生乱码一般都是由于编码格式不一样导致的. 打开Window-Preferences-General-content Types-T ...

  3. spring boot项目,application.properties配置文件下中文乱码解决方案

    转自:https://blog.csdn.net/qq_40408534/article/details/79831807 如以上,application.properties文件下中文乱码.发生乱码 ...

  4. spring boot 加载application配置文件

    这就要注意了

  5. Spring Boot加载配置文件

    问题1:Spring如何加载配置,配置文件位置? 1.默认位置: Spring Boot默认的配置文件名称为application.properties,SpringApplication将从以下位置 ...

  6. 【Java Web开发学习】Spring加载外部properties配置文件

    [Java Web开发学习]Spring加载外部properties配置文件 转载:https://www.cnblogs.com/yangchongxing/p/9136505.html 1.声明属 ...

  7. spring boot 加载配置 文件

    在springboot启动的过程中,默契情况下会在classpath路径下加载application.properties当做系统配置文件,但有时候我们想要替换成另一个文件,可以 通过以下方式:   ...

  8. spring boot 加载web容器tomcat流程源码分析

    spring boot 加载web容器tomcat流程源码分析 我本地的springboot版本是2.5.1,后面的分析都是基于这个版本 <parent> <groupId>o ...

  9. Eclipse下SpringBoot没有自动加载application.properties文件

    Eclipse内创建SpringBoot项目,在java/main/resources文件夹下面创建application.properties配置文件,SpringApplication.run后发 ...

随机推荐

  1. Python面向对象 | 抽象类和接口类

    一.抽象类(规范的编程模式) 什么是抽象类 抽象类是一个特殊的类,它的特殊之处在于只能被继承,不能被实例化.抽象类的本质还是类,指的是一组类的相似性,而接口只强调函数属性的相似性. 为什么要有抽象类 ...

  2. browserslist详解

    https://www.jianshu.com/p/d45a31c50711 https://juejin.im/post/5b8cff326fb9a019fd1474d6 https://githu ...

  3. IE和火狐的事件机制有什么区别

    1.IE的事件流是冒泡流,火狐支持冒泡流和捕获流. 2.阻止事件冒泡:IE---e.cancelBubble = true;    火狐---e.stopPropagation();

  4. Qt常用类——Qpoint

    QPoint 类代表一个坐标点,实现在 QtCore 共享库中.它可以认为是一个整型的横坐标和一个整型的纵坐标的组合. 构造 QPoint 类支持以下两种构造方式: QPoint(); // 构造横纵 ...

  5. 优先队列优化的 Huffman树 建立

    如果用vector实现,在运行时遍历寻找最小的两个节点,时间复杂度为O(N^2) 但是我们可以用priority_queue优化,达到O(N logN)的时间复杂度 需要注意的是priority_qu ...

  6. 【JZOJ6236】【20190628】启程的日子

    题目 给你一个\(n \times m\)的01矩阵 你需要用一些矩阵加减出这个矩阵 求最少的步数,并输出方案 需要满足构造出的01矩阵是一个四联通块 $ n ,  m \le 500 $ 题解 答案 ...

  7. 【BZOJ4722】由乃

    [BZOJ4722]由乃 题面 bzoj 题解 考虑到区间长度为\(14\)时子集个数\(2^{14}>14\times 1000\),由抽屉原理,区间长度最多为\(13\)(长度大于这个值就一 ...

  8. CF461B Appleman and Tree

    CF461B Appleman and Tree 传送门 一道比较容易的树形DP. 考虑用\(dp[i][1]\)代表将\(i\)分配给\(i\)的子树内黑点的方案数,\(dp[i][0]\)代表将\ ...

  9. PatchMatchStereo可能会需要的Rectification

    在稠密三维重建中,rectification可以简化patch match的过程.在双目特征匹配等场景中其实也用得到,看了一下一篇论文叫< A Compact Algorithm for Rec ...

  10. Union 与 Union All 区别(抄的W3C School的,抄一遍就记住了!)

    Union ,UnionAll 俩都是用来合并两个或以上的查询结果集: Union操作符 :select语句中必须有相同的数列 (相等数量的列,不同结果集同一列的数据类型一致,列的顺序必须相同): u ...