详解String

引言

在java中每天都会使用String。对于String的特性和用法需要进行深入的了解

immutable(不可变)

阅读全文

Spring Resource

前言

Spring4+ mybatis3+springMVC。maven管理项目。在做支付项目需要用到密钥文件。需要在service中读取密钥文件路径。通用做法把密钥文件放到src/main/resources/common/aaa.pfx。在读取文件路径时遇到问题

方法一

阅读全文

java TreeMap学习

前言

TreeMap采用的是红黑树(基本上是平衡二叉树时间复杂度为O(logN))
也就是它的查找保证了效率。
频繁的新增删除会导致树结构的移动变更树操作效率低下。

comparable comparator

在分析TreeMap之前先要了解一下这两个接口。他们是TreeMap的经常用到的工具方法

阅读全文

破窗理论

描述

不要放任“破窗户”(不好的设计,错误的决定或糟糕的代码)不管。要尽量在发现时立刻修复。
如果没有足够的时间进行适当的修复,就先把它保留起来。可以把出问题的代码放到注释中,
或是显示“未实现”消息,也可用虚拟数据加以替代。总之,要采取一些措施,防止进一步的恶化。
表明局势尚在掌控之中。有许多整洁良好的系统在出现“破窗”之后立马崩溃。
虽然促使软件崩溃的原因还有其他因素(我们将在其他地方接触到),但对“破窗”置之不理,
肯定会更快地加速系统崩溃。

阅读全文

减少IF

原文已经收入到笔记中名称是Anti-If: The missing patterns

Around 10 years ago I encountered the anti-if campaign and found it to be an absurd concept. How on earth would you make a useful program without using an if statement? Preposterous.

阅读全文

代码生成分析

BaseController

主要负责页面额跳转,不负责逻辑所以最主要的是进行异常处理
这样就可以使用Spring 注解进行异常处理,@ExceptionHandler(其中的一个限制就是进行异常处理的方法必须与出错的方法在一个类中)

@ExceptionHandler
public ModelAndView exception(HttpServletRequest request, Exception e) {
e.printStackTrace();
// 根据不同的异常类型进行不同处理
if (e instanceof ControllerException)
return new ModelAndView(“error”).addObject(“message”, “C->” + e.getMessage());
else
return new ModelAndView(“error”).addObject(“message”, “N->” + e.getMessage());
}`

这个才是正常的写法只处理RuntimeException

阅读全文

org.apache.commons.httpclient学习

org.apache.commons.httpclient学习

初始化连接管理器参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private static String DEFAULT_CHARSET = "GBK";
/** 连接超时时间,由bean factory设置,缺省为8秒钟 */
private int defaultConnectionTimeout = 8000;
/** 回应超时时间, 由bean factory设置,缺省为30秒钟 */
private int defaultSoTimeout = 30000;
/** 闲置连接超时时间, 由bean factory设置,缺省为60秒钟 */
private int defaultIdleConnTimeout = 60000;
//默认每个主机最大连接数
private int defaultMaxConnPerHost = 30;
//默认最大连接数
private int defaultMaxTotalConn = 80;
/** 默认等待HttpConnectionManager返回连接超时(只有在达到最大连接数时起作用):1秒 */
private static final long defaultHttpConnectionManagerTimeout = 3 * 1000;
/**
* 声明一个链接管理器,HTTP连接管理器,该连接管理器必须是线程安全的.
*/
private HttpConnectionManager connectionManager;

阅读全文

Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

阅读全文