Home

Git常用命令

基础配置 配置用户名 git config --global user.name "Your name" 配置邮箱 git config --global user.email "email@example.com" 配置颜色 git config --global color.ui true 配置命令别名 git config --global alias.alias_name command_name 正向流程 创建git仓库 git init 工作区增加或修改的文件,加入暂存区 git add file 暂存区提交到本地仓库当前分支 git commit git commit -m "comment" 删除操作加入暂存区 git rm file ...

Read more

Java动态代理使用

前置环境 有如下接口Worker public interface Worker { String work(String string); } 实现一个PrintWorker,工作是把输入的参数输出到控制台并返回 public class PrintWorker implements Worker { @Override public String work(String string) { System.out.println(string); return string; } } 通过动态代理,实现在work方法被调用之前,增加时间戳的打印 JDK 动态代理 调用代理...

Read more

Spring Validation自定义约束

完整实践案例 Maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> 定义约束注解 @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = CheckCorpusModeValidator.class) @Documented @Rep...

Read more

JVM内存区域

JVM规范 方法区(Method Area),用于存储已被虚拟机加载的类型信息、常量、静态变量、即时编译器编译后的代码缓存等数据 堆(Heap),此内存区域的唯一目的就是存放对象实例 虚拟机栈(VM Stack),虚拟机栈描述的是Java方法执行的线程内存模型:每个方法被执行的时候,Java虚拟机都会同步创建一个栈帧用于存储局部变量表、操作数栈、动态连接、方法出口等信息 本地方法栈(Native Method Stack),本地方法栈与虚拟机栈所发挥的作用是非常相似的,其区别只是虚拟机栈为虚拟机执行Java方法(也就是字节码)服务,而本地方法栈则是为虚拟机使用到的本地方法服务 程序计数器(Program Counter Register),可以看作是当前线程...

Read more

Spring Boot项目配置Servlet、Filter、Listener

代码实例 启动类增加注解@ServletComponentScan @SpringBootApplication @ServletComponentScan(value = "com.oliverclio.logger") public class EmqxHttpLoggerApplication { public static void main(String[] args) { SpringApplication.run(EmqxHttpLoggerApplication.class, args); } } 使用@WebFilter注解注册一个Filter @Order(1) @WebFilter(filterNa...

Read more

MyBatis-Plus实例

Maven依赖配置 pom.xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.2</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId>...

Read more

Java容器ArrayList源码分析

本文源码基于JDK8 数据结构 ArrayList的底层数据结构为对象数组 transient Object[] elementData; 初始化 初始化不显式指定初始容量,则默认容量为10,且数组暂不初始化,暂时使用共享空数组DEFAULTCAPACITY_EMPTY_ELEMENTDATA,等到有元素加入才初始化。如显式指定初始容量,且容量不为0,则马上按初始容量初始化。显式指定初始容量为0,则使用共享空数组EMPTY_ELEMENTDATA // 初始容量 private static final int DEFAULT_CAPACITY = 10; // 显式指定长度为0,使用此共享空数组 private static final...

Read more

Maven从聚合项目中引入配置

继承 继承聚合项目的所有配置 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.0</version> </parent> 引入依赖管理 只引入该聚合项目的<dependencyManagement>部分 只能在<dependencyManagement>中引入,配合<type>pom</type>和<s...

Read more

Maven插件使用

引入一个插件 <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> 执行插件目标 需要手动运行命令执行 或绑定生命周期 <build> <plugins&g...

Read more

Spring MVC 集成测试

独立测试profile 设置测试独立使用的配置,例如测试数据库的连接池配置 application-test.yml spring: datasource: username: root password: mysqlrootroot url: jdbc:mysql://192.168.88.13:3306/language_trainer_test?characterEncoding=utf-8&useSSL=true&serverTimeZone=Asia/Shanghai driver-class-name: com.mysql.cj.jdbc.Driver druid: i...

Read more