代码块¶
提供各种组件演示,以代码块的形式编写;使用多项目架构
项目结构¶
|--code-blocks::根项目, 不写任何代码,仅仅整合所有子项目
|--code-blocks-common::通用模块
|--code-blocks-spring::基于spring通用模块
|--code-blocks-springboot::基于springboot通用模块
新特性¶
code-blocks-common¶
版本:0.1.2
- 异常类的定义
- Juint的使用
- 枚举的定义
- rpc
- cglib.jdk: jdk动态代理,实现接口InvocationHandler
- cglib.cglib: cglib动态代理,实现即接口MethodInterceptor
- cglib.demo: 静态代理、动态代理demo
- JsonUtils: jackson的json的使用
- TreeUtils: 树构建与解析
- ListUtils: 排序
- CommonUtils: 字符串长度校验、BigDecimal转换String长度校验
- Base64Utils: Jdk Base64 编码解码
- RsaUtils: RSA 非对称加密解密
- AesUtils: AES 对称加密解密
- DataTypeUtils: 字符串转byte[32], byte[32]转字符串
版本:0.1.2
- PropertyUtils: 读取配置文件
- JsonUtils: 更新jackson使用的配置,初始化变量
版本:0.1.3
- ThreadPoolUtils: 线程池的使用
- JsonUtils:增加泛型转换
jdk动态代理与cglib动态代理区别¶
JDK的动态代理机制只能代理接口类,而非接口类无法实现JDK的动态代理,它的原理是通过 Proxy.newProxyInstance 创建的代理对象是在jvm运行时动态生成的一个对象,它并不是我们的InvocationHandler类型,也不是我们定义的那组接口的类型,而是在运行时动态生成的一个对象,并且命名方式都是这样的形式,以$开头,”proxy”在中间,最后一个数字表示对象的标号;
cglib是针对类来实现代理的,它的原理是对指定的目标类生成一个子类,并覆盖其中方法实现增强,但因为采用的是继承,所以不能对final修饰的类进行代理;
code-blocks-springboot¶
版本:0.1.1
- aspect: 实现日志拦截
- 实现CommandLineRunner接口:启动后执行一类操作
- 实现ApplicationContextAware接口:通过获取context取得bean
- 实现定时任务
- springboot加载spring的xml文件请使用以下两种方式
- @ImportResource(locations={”classpath:codeBolcksSpringbootApplicationContext.xml”})
- ClassPathXmlApplicationContext方法,见code-blocks-spring的BaseServiceImpl.java
版本:0.1.3
- HttpAspect:优化aop日志
- CommonExceptionHandler:增加aop异常处理
- @Valid @Validated: 增加校验使用方式
- mybatis:增加mybatis数据库字段转驼峰
版本:0.1.4
- HttpFilter:请求拦截过滤器,处理网关模式下跨域
- CrosConfig:通用跨域处理
code-blocks-designpattern¶
版本:0.1.1
序号 | 模式&描述 | 包括 |
---|---|---|
1 |
创建型模式 这些设计模式提供了一种在创建对象的同时隐藏创建逻辑的方式, 而不是使用 new 运算符直接实例化对象。 这使得程序在判断针对某个给定实例需要创建哪些对象时更加灵活。 |
工厂模式(Factory Pattern) 抽象工厂模式(Abstract Factory Pattern) 单例模式(Singleton Pattern) 建造者模式(Builder Pattern) 原型模式(Prototype Pattern |
2 |
结构型模式 这些设计模式关注类和对象的组合。 继承的概念被用来组合接口和定义组合对象获得新功能的方式。 |
适配器模式(Adapter Pattern) 桥接模式(Bridge Pattern) 过滤器模式(Filter、Criteria Pattern) 组合模式(Composite Pattern) 装饰器模式(Decorator Pattern) 外观模式(Facade Pattern) 享元模式(Flyweight Pattern) 代理模式(Proxy Pattern) |
3 |
行为型模式 这些设计模式特别关注对象之间的通信。 |
责任链模式(Chain of Responsibility Pattern) 命令模式(Command Pattern) 解释器模式(Interpreter Pattern) 迭代器模式(Iterator Pattern) 中介者模式(Mediator Pattern) 备忘录模式(Memento Pattern) 观察者模式(Observer Pattern) 状态模式(State Pattern) 空对象模式(Null Object Pattern) 策略模式(Strategy Pattern) 模板模式(Template Pattern) 访问者模式(Visitor Pattern) |
4 |
J2EE 模式 这些设计模式特别关注表示层。这些模式是由 Sun Java Center 鉴定的。 |
MVC 模式(MVC Pattern) 业务代表模式(Business Delegate Pattern) 组合实体模式(Composite Entity Pattern) 数据访问对象模式(Data Access Object Pattern) 前端控制器模式(Front Controller Pattern) 拦截过滤器模式(Intercepting Filter Pattern) 服务定位器模式(Service Locator Pattern) 传输对象模式(Transfer Object Pattern) |