Home

Java容器ArrayList源码完整注释

本文源码基于JDK8 ArrayList类继承关系 Iterator接口 public interface Iterator<E> { // 检测是否还有下一个元素 boolean hasNext(); // 返回下一个元素 E next(); // 将上一次next方法返回的元素删除 default void remove() { // 抛出异常 throw new UnsupportedOperationException("remove"); } // 对剩余的所有元素调用Consumer default void forEachRemaining(...

Read more

Spring声明式事务

代码实例 上下文配置类上加上@EnableTransactionManagement注解 @Configuration @EnableTransactionManagement public class RootConfig { } 注册DataSourceTransactionManager @Bean public DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource) { DataSourceTransactionManager manager = new DataSourceTransactionManager(); manager.s...

Read more

DBCP数据库连接池使用

maven依赖 <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-dbcp2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>...

Read more

Spring Security使用

本文例子基于前后端不分离项目 Maven依赖 <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>5.2.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId&...

Read more

MyBatis使用SQL查询

定义Mapper接口 @Repository public interface UserLoginLogMapper { Long getLoginLogCountByLoginTime(@Param("userId")Integer userId, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); } 编写SQL XML文件默认放在与Mapper接口同路径下 如Mapper接口在com.oliverclio.languagetrainer.mapper包下,则XML文件放在路径/resources/com/oliverclio/la...

Read more

Spring整合MyBatis

maven依赖 <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.2</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>2.0.2</version&...

Read more

正则表达式使用

Java代码例子 取出字符串中第一段数字和第一段中文 Pattern getNumberPattern = Pattern.compile("\\D*(\\d+)\\D*"); Pattern getChinesesPattern = Pattern.compile("[^\u4E00-\u9FA5]*([\u4E00-\u9FA5]+)[^\u4E00-\u9FA5]*"); Matcher matcher = null; //项目负责人及联系电话 String fzrdh = ((String)resultMap.get( "FZRDH")); //区分人名与电话,人名与电话混合且无规律 if(fzrdh != null && !fzrdh.equals("")...

Read more

Java 各进制数字字面量表示与输出

十进制 int a = 88; System.out.println(a); 二进制 JDK7以后可用 int a = 0b01011000; System.out.println(Integer.toBinaryString(a)); 八进制 int a = 0130; System.out.println(Integer.toOctalString(a)); 十六进制 int a = 0x58; System.out.println(Integer.toHexString(a));

Read more

Linux指定静态IP

操作例子 以CentOS 7为例 vi /etc/sysconfig/network-scripts/ifcfg-ens33 修改内容 BOOTPROTO="static" # 使用静态IP地址,默认为dhcp IPADDR="192.168.88.9" # 设置的静态IP地址 NETMASK="255.255.255.0" # 子网掩码 GATEWAY="192.168.88.88" # 网关地址 DNS1="192.168.88.88" # DNS服务器 重启网络服务 service network restart

Read more

Linux基本使用

命令 多命令执行 # 顺序执行 command1;command2;command3 # 条件执行,command1执行成功则继续执行command2 command1 && command2 # 条件执行,command1执行失败则执行command2 command1 || command2 文件基本操作 # 显示当前文件夹路径 pwd # 查看当前文件夹内容 ls ls -al ll # 改变当前文件夹路径 cd /opt # 创建文件夹 mkdir newDirectory # 递归创建文件夹 mkdir -p /opt/inner/newDirectory # 新建文件 touch a.txt # 查看文件内容 cat a.txt # 编...

Read more