guava参考文档
google guava开源工具框架的介绍,供开发过程中参考用,非常方便。
Spring3中配置DBCP,C3P0,Proxool,Bonecp数据源
在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面包含这些数据源的jar文件和依赖文件及配置文件。。
如Bonecp目前听说是最快的数据源,速度是传统的c3p0的25倍,
bonecp.properties文件:
bonecp.driverClass=org.gjt.mm.mysql.Driver
bonecp.jdbcUrl=jdbc:mysql://localhost/manytomany?useUnicode=true&characterEncoding=UTF-8
bonecp.username=root
bonecp.password=2008
#分区数量
bonecp.partitionCount = 1
#每个分区含有的最小连接数
bonecp.minConnectionsPerPartition = 1
#每个分区含有的最大连接数
bonecp.maxConnectionsPerPartition = 2
#每次新增连接的数量
bonecp.acquireIncrement = 1
#连接池阀值,当 可用连接/最大连接 < 连接阀值 时,创建新的连接
bonecp.poolAvailabilityThreshold = 20
#连接超时时间阀值,获取连接时,超出阀值时间,则获取失败,毫秒为单位
bonecp.connectionTimeout = 10000
#连接池助手线程数量,可设置为0,该参数会降低运行速度,但程序有大量连接时,有助于提升高并发程序的性能
bonecp.releaseHelperThreads = 0
#语句助手线程数,可设置为0,该参数会降低运行速度,但程序有大量的查询语句时,有助于提升高并发程序的性能
bonecp.statementReleaseHelperThreads = 0
#测试连接有效性的间隔时间,单位分钟
bonecp.idleConnectionTestPeriod = 60
#连接的空闲存活时间,当连接空闲时间大于该阀值时,清除该连接
bonecp.idleMaxAge = 240
#语句缓存个数,默认是0
bonecp.statementsCacheSize = 5
Spring中的配置信息
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.mvc" />
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:default-servlet-handler />
<aop:config proxy-target-class="true"/>
<tx:annotation-driven transaction-manager="txManager"/>
<!-- 采用单数据源事务控制方式,通过注解来定义事务-->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:proxool.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource" destroy-method="close">
<property name="driver">
<value>org.gjt.mm.mysql.Driver</value>
</property>
<property name="driverUrl">
<value>jdbc:mysql://localhost/manytomany?useUnicode=true&characterEncoding=UTF-8</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>2008</value>
</property>
<property name="alias">
<value>Db_name</value>
</property>
<property name="houseKeepingSleepTime">
<value>90000</value>
</property>
<property name="prototypeCount">
<value>50</value>
</property>
<property name="maximumConnectionCount">
<value>50</value>
</property>
<property name="minimumConnectionCount">
<value>2</value>
</property>
<property name="trace">
<value>true</value>
</property>
<property name="verbose">
<value>true</value>
</property>
</bean>
</beans>
轻量级java web MVC框架
一个非常简单的MVC框架,实现了类似Spring MVC的基本功能。
1、包括自动扫描绑定映射路径,只要在web.xml中指定扫描包,系统启动后会将请求url绑定到指定的处理方法上。如:
在web.xml中定义如下:
<context-param>
<param-name>ScanPackage</param-name>
<param-value>com.mvc.controller</param-value>
</context-param>
容器在启动时候,会将com.mvc.controller下所有映射路径绑定处理方法上,假如在扫描包中定义下列类:
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.hxw.simple.light.mvc.annotation.MappingMethodAnnotation;
import com.hxw.simple.light.mvc.view.SimpleModelView;
import com.mvc.verification.VerificationCode;
public class LoginController {
@MappingMethodAnnotation(mappingMethod = "/login.do")
public String login(HttpServletRequest request, HttpServletResponse response) {
return "login/main";
}
@MappingMethodAnnotation(mappingMethod = "/loginvm.do")
public SimpleModelView loginView(HttpServletRequest request,
HttpServletResponse response) {
SimpleModelView mv = new SimpleModelView("login/mainmv");
Map<String, String> m = new HashMap<String, String>();
m.put("beij", "北京");
m.put("sha", "上海");
m.put("nanj", "南京");
mv.setAttribute("city", m);
return mv;
}
@MappingMethodAnnotation(mappingMethod = "/Verify.do")
public void service(HttpServletRequest arg0, HttpServletResponse arg1)
throws IOException {
HttpServletRequest request = (HttpServletRequest) arg0;
HttpServletResponse response = (HttpServletResponse) arg1;
response.setContentType("image/jpeg");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
VerificationCode vCode = new VerificationCode();
BufferedImage bufferImage = vCode.getImageData();
HttpSession session = request.getSession();
response.addCookie(new Cookie("JSSESIONID", session.getId()));
ServletOutputStream responseOutputStream = response.getOutputStream();
ImageIO.write(bufferImage, "JPEG", responseOutputStream);
responseOutputStream.flush();
responseOutputStream.close();
}
}
那么在接到url请求如:http://localhost:8080/TestSimpleMVC/loginvm.do
会调用指定的方法处理。
2、支持视图定义,在web.xml定义了视图路径后:
<servlet>
<servlet-name>DelegateForwardServlet</servlet-name>
<servlet-class>com.hxw.simple.light.mvc.servlet.DelegateForwardServlet</servlet-class>
<init-param>
<param-name>prefix</param-name>
<param-value>/WEB-INF/view/</param-value>
</init-param>
<init-param>
<param-name>suffix</param-name>
<param-value>.jsp</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DelegateForwardServlet</servlet-name>
<url-pattern>/SYS_FORWARD_URL.fo</url-pattern>
</servlet-mapping>
只需在执行完方法后,返回字符串:如return "login/main"就会跳转到指定视图,还可以在视图中用EL表单式访问modelview数据,例子如:
SimpleModelView mv = new SimpleModelView("login/mainmv");
Map<String, String> m = new HashMap<String, String>();
m.put("beij", "北京");
m.put("sha", "上海");
m.put("nanj", "南京");
mv.setAttribute("city", m);
return mv;
3、支持数据参数自动绑定如:
@ParamAttribute(type = ParamaAttributeType.REQUEST, key = "userPassword") String s,
@ParamAttribute(type = ParamaAttributeType.SESSION, key = "11212") String s1,
@ParamAttribute(type = ParamaAttributeType.SERVLETCONTEXT, key = "32312") String s2,
@ParamAttribute(type = ParamaAttributeType.REQUEST, key = "userNames") String[] s3
系统根据参数指定的范围,这指定范围内赋值到参数上,你还可以直接使用javabean做参数绑定,如:
public class User extends PaginatedHelper {
private static final long serialVersionUID = -8225389551152428829L;
private String userName;
private String userPassword;
public User() {
super();
}
public User(String userName, String userPassword) {
super();
this.userName = userName;
this.userPassword = userPassword;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
在方法上带上 Uer user后,属性名称相同的数据就会赋值到javabean上。不必再使用繁琐的user.setUserName(request.getParameter("userName"));
3、简便的jdbc操作
有查询模板QueryTemplate,命名查询NamedQueryTemplate及bean作为参数的BeanQueryTemplate等。支持返回javabean类型,javabean列表,
MAP类型,map列表类型,统计结果queryForInt等。
css 2.0 中文手册
开发人员和入门者查找很实用,方便css中文手册技术文档。
Windows游戏编程大师技巧
这是一本快速提高自己Windows编程能力的好书.