代码改变世界

随笔档案-2012年12月

Spring 3 MVC And JSR303 @Valid Example

2012-12-27 20:19 by Rollen Holt, 3781 阅读, 收藏, 编辑
摘要: package com.xxx.training.controller;import com.xxx.training.model.User;import org.springframework.stereotype.Controller;import org.springframework.val... 阅读全文

Spring 表单处理

2012-12-27 19:27 by Rollen Holt, 3313 阅读, 收藏, 编辑
摘要: 1. SimpleFormController vs @ControllerIn XML-based Spring MVC web application, you create a form controller by extending theSimpleFormControllerclass.In annotation-based, you can use@Controllerinstead.SimpleFormControllerpublic class CustomerController extends SimpleFormController{ //...}Annota... 阅读全文

Spring MVC视图解析器:配置多个视图解析器的优先级

2012-12-27 17:08 by Rollen Holt, 26749 阅读, 收藏, 编辑
摘要: 问题在Spring MVC应用程序中,我们经常需要应用一些视图解析器策略来解析视图名称。例如,联合使用三个视图解析器:InternalResourceViewResolver、ResourceBundleViewResolver和XmlViewResolver。但是,如果返回了一个视图的名称,那么,... 阅读全文

Spring MVC视图解析器:Spring MVC ResourceBundleViewResolver示例

2012-12-27 17:00 by Rollen Holt, 7294 阅读, 收藏, 编辑
摘要: 在Spring MVC中,使用ResourceBundleViewResolver基于“.properties”文件中的视图bean来解析“视图名称”。默认地,ResourceBundleViewResolver将从位于项目class路径根目录下的文件views.properties中加载视图bea... 阅读全文

Spring MVC视图解析器:Spring MVC XmlViewResolver示例

2012-12-27 16:35 by Rollen Holt, 8638 阅读, 收藏, 编辑
摘要: 在Spring MVC中,使用XmlViewResolver基于XML文件中的视图bean来解析“视图名称”。默认地,XmlViewResolver将从/WEB-INF/views.xml中加载视图bean,不过,这个位置可以通过“location”属性覆盖:<beans ...> <bean class="org.springframework.web.servlet.view.XmlViewResolver"> <property name="location"> <value>/WEB-INF/spr 阅读全文

Spring中bean注入前后的一些操作:

2012-12-27 10:47 by Rollen Holt, 3444 阅读, 收藏, 编辑
摘要: InitializingBean 和DisposableBeaninit-method 和destroy-method@PostConstruct 和@PreDestroyIn Spring,InitializingBeanandDisposableBeanare two marker interfaces, a useful way for Spring to perform certain actions upon bean initialization and destruction.For bean implemented InitializingBean, it will runaf 阅读全文

Spring的属性依赖检查

2012-12-27 10:40 by Rollen Holt, 2969 阅读, 收藏, 编辑
摘要: Spring支持4种依赖检查:默认的是nonenone – No dependency checking.simple – If any properties of primitive type (int, long,double…) and collection types (map, list..) have not been set, UnsatisfiedDependencyException will be thrown.objects – If any properties of object type have not been set, UnsatisfiedDependenc 阅读全文

Spring中为bean注入Date对象

2012-12-27 10:13 by Rollen Holt, 4977 阅读, 收藏, 编辑
摘要: 比如我们有下面的一个bean:import java.util.Date; public class Customer { Date date; public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } @Override public String toString() { return "Customer [date=" + date + "]"; } } 注意我们上面的bean中有一个Date,但是如果我们使用下面的配置:& 阅读全文

Spring中bean配置的继承

2012-12-27 09:50 by Rollen Holt, 6210 阅读, 收藏, 编辑
摘要: In Spring, the inheritance is supported in bean configuration for a bean to share common values, properties or configurations.A child bean or inherited bean can inherit its parent bean configurations, properties and some attributes. In additional, the child beans are allow to override the inherited 阅读全文

Spring中注入List,Set,Map,Properties

2012-12-27 09:44 by Rollen Holt, 54240 阅读, 收藏, 编辑
摘要: 下面的例子展示了如何注入List – <list/>Set – <set/>Map – <map/>Properties – <props/>Spring beansimport java.util.List;import java.util.Map;import java.util.Properties;import java.util.Set; public class Customer { private List<Object> lists; private Set<Object> sets; private Ma 阅读全文

Spring中bean的范围

2012-12-27 09:37 by Rollen Holt, 1656 阅读, 收藏, 编辑
摘要: Spring中有5种bean的范围:5 types of bean scopes supported :singleton – Return a single bean instance per Spring IoC container 这个范围也是默认的prototype – Return a new bean instance each time when requestedrequest – Return a single bean instance per HTTP request. *session – Return a single bean instance per HTTP s 阅读全文

Spring中使用inner bean

2012-12-27 09:29 by Rollen Holt, 2206 阅读, 收藏, 编辑
摘要: 有点类似java 内部类。看个demo。假设有下面的一个bean:public class Customer { private Person person; public Customer(Person person) { this.person = person; } public void setPerson(Person person) { this.person = person; } @Override public String toString() { return "Customer [person=" + person + "]"; 阅读全文

spring中3中为bean注入值的办法总结

2012-12-27 09:25 by Rollen Holt, 994 阅读, 收藏, 编辑
摘要: 有三种办法,分别是:Normal wayShortcut“p” schema假设我们现在有这么一个bean:public class FileNameGenerator { private String name; private String type; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getType() { return type; } public void setType(String typ... 阅读全文

使用Spring的JavaConfig

2012-12-27 09:16 by Rollen Holt, 8530 阅读, 收藏, 编辑
摘要: 之前我们都是在xml文件中定义bean的,比如:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"& 阅读全文

关于使用"/"来 dispatcherServlet 的url-pattern带来的问题

2012-12-26 15:47 by Rollen Holt, 14702 阅读, 收藏, 编辑
摘要: 之前一直使用*.do来做的,但是绝的*.do很丑,于是就改用“/”来配置: <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> < 阅读全文

Spring MVC POST中文乱码解决方案

2012-12-26 13:47 by Rollen Holt, 48040 阅读, 收藏, 编辑
摘要: POST中文乱码解决方案以前,我都是自己编写一个filter,来实现编码,代码如下: 1 public class CharacterEncodingFilter implements Filter { 2 3 private final static Logger log= Logger... 阅读全文

spring MVC中定义异常页面

2012-12-25 17:11 by Rollen Holt, 22981 阅读, 收藏, 编辑
摘要: 如果我们在使用Spring MVC的过程中,想自定义异常页面的话,我们可以使用DispatcherServlet来指定异常页面,具体的做法很简单:下面看我曾经的一个项目的spring配置文件: ... 阅读全文

agentzh 的 Nginx 教程--资料分享

2012-12-23 22:24 by Rollen Holt, 1206 阅读, 收藏, 编辑
摘要: 本次分享的资料是关于nginx的教程,虽然我一直计划着要学习Nginx的,但是一直没时间,也没这个需求。于是就搁浅了,今天在微薄上看到这个,所以就发出来,先收藏者,等用到了的时候,就可以学习了。推荐大家去这里看:http://agentzh.org/misc/nginx/agentzh-nginx-tutorials-zhcn.htmlagentzh 的 Nginx 教程(版本 2012.09.27)目录缘起Nginx 教程的连载计划Nginx 变量漫谈(一)Nginx 变量漫谈(二)Nginx 变量漫谈(三)Nginx 变量漫谈(四)Nginx 变量漫谈(五)Nginx 变量漫谈(六)Ngi 阅读全文

关于jsp中使用jstl的问题

2012-12-23 13:23 by Rollen Holt, 5888 阅读, 收藏, 编辑
摘要: 今天在jsp中使用jstl标签库的时候,出现了一个很恶心的问题,我记得自己几年前在学校学这门课的时候,没遇到过这种问题的啊,现在突然出现,确实恶心了我一把。一般稍不小心就会出现下面的错误: the absolute uri:http://java.sun.com/jstl/core cannot be resolved.一个例子如:http://stackoverflow.com/questions/4928271/jstl-1-2-the-absolute-uri-http-java-sun-com-jstl-core-cannot-be-resolved解决办法: 如果你的项目是使用M.. 阅读全文

SQLBuilder

2012-12-09 20:50 by Rollen Holt, 4616 阅读, 收藏, 编辑
摘要: 之前因为工作的需要,参考apache commons-lang中的Builder思想,采用java语言编写了SQLBuilder,项目主页:http://rollenholt.github.com/SQLBuilder/不过目前仅仅是一个雏形,本项目我业余时间维护。 阅读全文