
Java
junlon2006
Coding for fun.
展开
-
Spring boot + docker运行时定制环境变量
1、目的在docker run时,导入一个运行时参数到Spring boot application中。2、方式采用环境变量,以变量HELLO_WORLD为类3、步骤step 1. Dockerfile中添加ENVHELLO_WORLD="this is default hello world"step 2. Spring Boot中获取环境变量:@Config...原创 2020-03-12 11:50:07 · 2507 阅读 · 0 评论 -
Java String equals
以下源码摘至JDK1.8 public boolean equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof String) { String anotherString =...原创 2019-10-16 11:34:24 · 183 阅读 · 0 评论 -
Java switch String
switch String支持底层实现switch (type) { case "hello": System.out.println("hello"); break; case "world": System.out.println("world"); break;}switch (type) { case "hello".hashcode: if ("hello".eq...原创 2019-10-14 15:55:16 · 166 阅读 · 0 评论 -
Java String拼接
常用的字符串拼接方式有五种,分别是使用+、使用concat、使用StringBuilder、使用StringBuffer以及使用StringUtils.join。由于字符串拼接过程中会创建新的对象,所以如果要在一个循环体中进行字符串拼接,就要考虑内存问题和效率问题。因此,经过对比,我们发现,直接使用StringBuilder的方式是效率最高的。因为StringBuilder天生就是设计来定义可...原创 2019-10-14 15:22:11 · 370 阅读 · 0 评论 -
Java 装箱与拆箱
Java中的八种基本数据类型和对应的包装类基本数据类型包装类byteByteshortShortlongLongintIntegerboolenBoolencharCharactorfloatFloatdoubleDouble public static void main(String[]args){ ...原创 2019-10-14 11:30:57 · 95 阅读 · 0 评论 -
Java Integer cache
在Integer自动装箱过程中,为了节省内存,JDK做了cache,对-128 ~ 128做cache /** * Returns an {@code Integer} instance representing the specified * {@code int} value. If a new {@code Integer} instance is not ...原创 2019-10-12 19:57:10 · 164 阅读 · 0 评论 -
Java String hashcode
/** * Returns a hash code for this string. The hash code for a * {@code String} object is computed as * <blockquote><pre> * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]...原创 2019-10-12 10:36:01 · 145 阅读 · 0 评论 -
Java Collection HashSet
1、HashSet底层实现为HashMap,不能插入重复的元素。2、HashSet将元素作为HashMap的Key,HashMap的Value是一个默认的静态对象。JDK1.8部分源码如下:public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable,...原创 2019-10-11 20:30:03 · 182 阅读 · 0 评论 -
spring boot 解决中文乱码问题
package com.unisound.iot.unione.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.http.converter.Htt...原创 2019-07-11 10:51:37 · 738 阅读 · 0 评论 -
Java Collection ArrayList
/** * Inserts the specified element at the specified position in this * list. Shifts the element currently at that position (if any) and * any subsequent elements to the right (adds one...原创 2019-10-08 15:32:51 · 123 阅读 · 0 评论 -
Java Collection LinkedList
LinkedList本质上是一个双项链表,插入、删除复杂度O(1),查找复杂度O(N)以下为从JDK摘录的部分源码/* Node节点使用泛型,数据结构如下 */private static class Node<E> { E item; Node<E> next; Node<E> prev; ...原创 2019-10-09 19:06:49 · 125 阅读 · 0 评论 -
Java Collection Stack
Stack即栈,后进先出以下为从JDK摘录的部分源码(接口线程安全)/** * Pushes an item onto the top of this stack. This has exactly * the same effect as: * <blockquote><pre> * addElement(item)</p...原创 2019-10-10 10:33:59 · 169 阅读 · 0 评论 -
Java Collection modCount
在很多的结构中(ArrayList、LinkedList、PriorityQueue等),这些结构的特点就是:线程不安全,它们都有modCount字段,从字面上看该modCount保持了结构被修改的次数,这个次数有什么用呢?下面以JDK ArrayList为例,看看modCount有什么作用/** * An optimized version of AbstractList.Itr...原创 2019-10-10 14:02:21 · 281 阅读 · 0 评论 -
Java Collection PriorityQueue
PriorityQueue即队列,先进先出/** * Increases the capacity of the array. * * @param minCapacity the desired minimum capacity */ private void grow(int minCapacity) { int oldCapa...原创 2019-10-10 15:51:38 · 175 阅读 · 0 评论 -
Java基础知识总结
1、JAVA本质上只有值传递(主要分为两种,基础类型,引用类型)2、String、StringBuffer、StringBuilder的区别:2.1、String不可变public final class String implements java.io.Serializable, Comparable<String>, CharSequence { /** T...原创 2019-10-11 11:40:47 · 152 阅读 · 0 评论 -
Java RandomAccess interface
/* * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package java.util;/** * Marker interface...原创 2019-10-11 14:11:22 · 144 阅读 · 0 评论 -
Java Collection HashMap
HashMap线程不安全HashMap本质上是连续的数组 + 链表结构,在JDK1.8中,当table中的链表长度大于8时,会将链表转换为红黑树,以此来提升搜索的性能。如下图下面为摘录于JDK1.8中的部分源码1、初始table数组长度16,当存储的元素个数超过16 * 0.75时触发扩容,扩容逻辑为double,即容量扩充1倍。扩容时开销比较大,因为需要rehash,即将已存在的元素...原创 2019-10-11 16:32:54 · 159 阅读 · 0 评论 -
AOP
https://www.cnblogs.com/flowwind/p/4782606.htmlSpring AOPJava web 环境搭建Java web 项目搭建Java Spring IOC用法spring提供了两个核心功能,一个是IoC(控制反转),另外一个便是Aop(面向切面编程),IoC有助于应用对象之间的解耦,AOP则可以实现横切关注点(如日志、安全、缓存和事务管理)与他们...转载 2019-06-11 17:10:46 · 1870 阅读 · 0 评论 -
Spring Boot Actuator
https://www.jianshu.com/p/af9738634a21Spring Boot 的 Actuator 提供了很多生产级的特性,比如监控和度量Spring Boot 应用程序。Actuator 的这些特性可以通过众多 REST 接口、远程 shell 和 JMX 获得。一、Actuator 的 REST 接口Spring Boot Actuator 的关键特性是在应用...转载 2019-06-17 10:36:42 · 300 阅读 · 0 评论 -
Spring Cloud入门教程(一):服务治理(Eureka)
https://www.jianshu.com/p/d32ae141f680Spring Cloud是一系列框架的集合,其基于Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,构建了服务治理(发现注册)、配置中心、消息总线、负载均衡、断路器、数据监控、分布式会话和集群状态管理等功能,为我们提供一整套企业级分布式云应用的完美解决方案。Spring Cloud包含了多个子...转载 2019-06-10 19:35:10 · 158 阅读 · 0 评论 -
Spring注解@Resource和@Autowired区别对比
转载于:https://www.cnblogs.com/think-in-java/p/5474740.html@Resource和@Autowired都是做bean的注入时使用,其实@Resource并不是Spring的注解,它的包是javax.annotation.Resource,需要导入,但是Spring支持该注解的注入。1、共同点两者都可以写在字段和setter方法上。两者如...转载 2019-02-26 14:04:10 · 259 阅读 · 0 评论 -
spring的@Transactional注解详细用法
转载于:https://www.cnblogs.com/yepei/p/4716112.html概述事务管理对于企业应用来说是至关重要的,即使出现异常情况,它也可以保证数据的一致性。Spring Framework对事务管理提供了一致的抽象,其特点如下:为不同的事务API提供一致的编程模型,比如JTA(Java Transaction API), JDBC, Hibernate, J...转载 2019-03-06 16:33:38 · 153 阅读 · 0 评论 -
使用注解来构造IoC容器
转载于:http://www.cnblogs.com/xdp-gacl/p/3495887.html用注解来向Spring容器注册Bean。需要在applicationContext.xml中注册<context:component-scan base-package=”pagkage1[,pagkage2,…,pagkageN]”/>。如:在base-package指明一个包...转载 2019-03-07 18:42:35 · 131 阅读 · 0 评论 -
MySQL macOS安装
转载于:http://www.cnblogs.com/macro-cheng/archive/2011/10/25/mysql-001.html一 下载MySQL 访问MySQL的官网http://www.mysql.com/downloads/然后在页面中会看到“MySQL Community Server”下方有一个“download”点击。进入MySQL的下载界面(h...转载 2019-03-12 11:45:52 · 1038 阅读 · 0 评论 -
转(JAVA的JNI调用)
转载于:https://www.cnblogs.com/GDUT/p/3806771.html由于JNI调用C和调用C++差不多,而且C++中可以混合写C代码,所以这里主要是写关于JNI调用C++的部分。 一般步骤: 先是写普通的Java类,其中包括本地方法调用。 然后编译这个Java类,调用javah命令,生成.h头文件 接着,就是实现头文件中的函数;实现过程中有点比较麻...转载 2019-05-13 10:50:26 · 3834 阅读 · 0 评论 -
@Aspect
https://blog.youkuaiyun.com/qgfjeahn/article/details/60144241Spring只支持XML方式而没有实现注解的方式(也叫AspectJ方式)的AOP,所以要使用@Aspect注解,只能引入AspectJ相关的 jar 包 aopalliance-1.0.jar 和 aspectjweaver.jar,这个坑把我给坑惨了。1使用步骤如下:1、引入...转载 2019-06-12 14:33:38 · 3044 阅读 · 0 评论 -
@Value
https://www.baeldung.com/spring-value-annotationI just announced the newLearn Springcourse, focused on the fundamentals of Spring 5 and Spring Boot 2:>> CHECK OUT THE COURSEIf you have a...转载 2019-06-13 14:51:43 · 425 阅读 · 0 评论 -
Feign
https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html7.Declarative REST Client: FeignFeignis a declarative web service client. It makes writing web service clients eas...转载 2019-06-13 14:56:27 · 1039 阅读 · 0 评论 -
@Controller @RestController
https://blog.youkuaiyun.com/gg12365gg/article/details/51345601知识点:@RestController注解相当于@ResponseBody + @Controller合在一起的作用。1) 如果只是使用@RestController注解Controller,则Controller中的方法无法返回jsp页面,或者html,配置的视图解析器 ...转载 2019-06-13 15:30:18 · 123 阅读 · 0 评论 -
Java equals() & hashCode()
https://www.cnblogs.com/Qian123/p/5703507.html阅读目录equals()方法详解 hashcode() 方法详解 Hashset、Hashmap、Hashtable与hashcode()和equals()的密切关系java.lang.Object类中有两个非常重要的方法: 1 2 publicboo...转载 2019-06-13 17:34:03 · 135 阅读 · 0 评论 -
@Qualifier
https://my.oschina.net/leisu/blog/916051背景我们知道,自动装配注入时,可以使用@Resource或者@Autowired注入bean。但有时候仅仅一个bean_id还无法清晰明确出要注入的bean,因此可以引入@Qualifier注解。在class类和bean注入时,都加上@Qualifier(),来达到注入某个...转载 2019-06-13 19:33:11 · 3707 阅读 · 0 评论 -
@PostConstruct
https://www.jianshu.com/p/98cf7d8b9ec31、从Java EE5规范开始,Servlet中增加了两个影响Servlet生命周期的注解,@PostConstruct和@PreDestroy,这两个注解被用来修饰一个非静态的void()方法。写法有如下两种方式:@PostConstructpublic void someMethod(){}或者pu...转载 2019-06-13 19:41:14 · 2351 阅读 · 0 评论 -
java中Class.getResource
https://www.cnblogs.com/keyi/p/6282838.html 用JAVA获取文件,听似简单,但对于很多像我这样的新人来说,还是掌握颇浅,用起来感觉颇深,大常最经常用的,就是用JAVA的File类,如要取得c:/test.txt文件,就会这样用File file = new File("c:/test.txt");这样用有什么问题,相信大家都知道,就是路径硬编码,对于...转载 2019-06-19 10:01:07 · 130 阅读 · 0 评论 -
@ControllerAdvice
https://www.cnblogs.com/magicalSam/p/7198420.html在spring 3.2中,新增了@ControllerAdvice 注解,可以用于定义@ExceptionHandler、@InitBinder、@ModelAttribute,并应用到所有@RequestMapping中。参考:@ControllerAdvice 文档一、介绍创建 MyC...转载 2019-06-14 19:01:02 · 1880 阅读 · 0 评论 -
Lombok
https://www.cnblogs.com/qnight/p/8997493.html前言Lombok是一种Java™实用工具,可用来帮助开发人员消除 Java 的冗长,尤其是对于简单的 Java 对象(POJO)。它通过注解实现这一目的。正文添加依赖在 pom.xml 文件中添加相关依赖:<lombok.version>1.16.20</...转载 2019-06-10 12:02:20 · 360 阅读 · 0 评论 -
@Builder
https://www.projectlombok.org/features/Builder@Builder... and Bob's your uncle: No-hassle fancy-pants APIs for object creation!@Builderwas introduced as experimental feature in lombok v0.12.0....转载 2019-06-10 14:38:51 · 2869 阅读 · 1 评论 -
转java中的注解大全@controller、@service、@repository等
转载于:http://www.cnblogs.com/hnrainll/archive/2011/10/11/2207773.html参考一篇文章,其中讲了@controller、@service、@repository注解,看后很有启发,自己复制下总结下,添加点东西写下这篇博客controller层使用@controller注解@Controller 用于标记在一个类上,使用它标记的类就...转载 2019-02-26 11:32:34 · 250 阅读 · 0 评论