摘要:今天碰到一个问题,页面表单上是一个id,但在表单控制器的command里是一个javabean,如果将一个String转换成javabean呢?因为已经有了一个服务于hibernate的javabean,我可不想再写一个javabean,然后再笨笨的转换。在查看SimpleFormController的API的时候,发现它有一个来自父类BaseCommandController的方法——initBinder:BaseCommandController (Spring Framework)initBinderprotected void initBinder(HttpServletRequest
阅读全文
随笔分类 - spring MVC3.0
spring MVC实践
摘要:I thought that it was time to take a look at Spring’s MVC interceptor mechanism, which has been around for a good number of years and is a really useful tool.A Spring Interceptor does what it says on the tin: intercepts an incoming HTTP request before it reaches your Spring MVC controller class, or
阅读全文
摘要:一、Servlet Filter与Spring interceptor的执行顺序 Filter有顺序吗?我们怎么控制filter的执行顺序。通过Tomcat的代码分析,servlet在Filter执行完成后才调用,如有多个filter怎么控制执行顺序,首先会想到在web.xml配置某个参数,例如order之类的,但查找一下一番,servlet并没有这个参数。试试filter Mapping的配置的先后顺序,果然有效,原来filter的执行顺序就考filter mapping在web.xml中的顺序。spring interceptor也是这样的执行顺序,不过interceptor多一个配置参数
阅读全文
摘要:在当今的MVC framework里,似乎Webwork2逐渐成为主流, Webwork2+SpringFramework的组合变得越来越流行。这似乎意味着Spring自带的MVC framework远比Webwork2差,所以大家纷纷用Webwork2来代替。确实,Spring的MVC framework不算是整个Spring的核心部件,但它的威力却超过了很多人的想象。很多人包括xiecc认为Spring的MVC framework是非常优秀的,甚至比Webwork2更优秀。下面列举一下Spring的MVC framework在设计时做出的一些重要的决定,并将之和相关的MVC framewo
阅读全文
摘要:假如我们在写一个基于Spring的普通应用程序,不管我们用了多么精妙的设计模式,进行了如何巧妙的设计,我们必须在某个地方执行这样的代码:ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml", "applicationContext-part2.xml"});appContext.getBean("…");也许这样的代码算不上丑陋,但是它无疑破坏了程序的纯洁
阅读全文
摘要:其实每个MVC framework的执行过程都是大同小异的,当个request过来时,它都通过一个Servlet来响应request,再根据request的路径名和配置将这个request dispatch给一个Controller执行,最后将之返回配置文件里对应的页面。在Spring MVC里,这个Servlet的名字叫DispatchServlet。稍看一下它的源码会发现这是一很简单的类。下面是DispatchServlet的类图:简单吧,这是典型的Template Method模式。每个类都会完成一些自己的本职工作,把不属于自己的工作延迟到子类来完成。这些类的子职责在下面会有分析。其实整
阅读全文
摘要:Spring 3.1 M1 is out with some veryuseful features. One of the coolest feature in the latest release is comprehensive Caching support!Spring Framework provides support for transparently adding caching into an existing Spring application. Similar to the transaction support, the caching abstraction al
阅读全文
摘要:Let us make a complete end-to-end application using Spring 3.0 MVC as front end technology and Hibernate as backend ORM technology. For this application we will also use Maven for build and dependency management and MySQL as database to persist the data.The application will be a simple Contact Manag
阅读全文
摘要:SpringMVC与Hibernate整合配置Spring3.0Hibernate3.0web.xml<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://j
阅读全文
摘要:This tutorial explains how to use annotations with spring 3 MVC and hibernate 3 based application to make the development easier and faster than ever before.ArticleService.javaThis is the interface which declares methods which will be used in controller class.packagenet.roseindia.service;importjava.
阅读全文
摘要:This tutorial explains how to use annotations with spring 3 MVC and hibernate 3 based application to make the development easier and faster than ever before.dispatcher-servlet.xml:<context:property-placeholder>element specifies the location where to find the properties file. In our case it is
阅读全文
摘要:This tutorial explains how to use annotations with spring 3 MVC and hibernate 3 based application to make the development easier and faster than ever before.Spring 3 MVC and Hibernate 3 Example application using AnnotationsThis tutorial explains how to use annotations with spring 3 MVC and hibernate
阅读全文
摘要:Java代码@InitBinderpublicvoidinitBinder(WebDataBinderbinder){SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy-MM-dd");dateFormat.setLenient(false);binder.registerCustomEditor(Date.class,newCustomDateEditor(dateFormat,true));binder.registerCustomEditor(SystemInfo.class,newPropertyEditorSu
阅读全文
摘要:Customizing WebDataBinder initializationTo customize request parameter binding with PropertyEditors, etc. via Spring's WebDataBinder, you can either use @InitBinder-annotated methods within your controller or externalize your configuration by providing a custom WebBindingInitializer.Customizing
阅读全文
摘要:弃用了struts2,用spring mvc框架做了几个项目,感觉都不错,而且使用了注解方式,可以省掉一大堆配置文件。本文主要介绍使用注解方式配置的spring mvc,之前写的spring3.0 mvc和rest小例子没有介绍到数据层的内容,现在这一篇补上。下面开始贴代码。文中用的框架版本:spring 3,hibernate 3,没有的,自己上网下。web.xml配置:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2
阅读全文
摘要:今番又遇到乱码问题,有时候真觉得英语母语的那些地区确实挺省事的,至少不用为了这个经典麻烦去折腾。网络上讨论乱码问题的文章很多,因为各作者使用的计算机环境的不同,往往不是很全面。这里非常推荐的一篇文章:http://dohkoos.name/java-garbled-analysis.html简而言之,乱码的“根本原因是由于编码和解码采用的不是同一种码”。例如作者所举的例子,使用GBK编码为UTF-8,使用ISO-8859从UTF-8解码,可能会导致乱码问题。这就好比有一篇中文文章想给王五看,不过这篇文章先由张三翻译成为了英文,然后再由李四翻译成俄文(而不是翻译回中文),但是王五只看得懂中文,于
阅读全文
摘要:转载出处:http://fuliang.iteye.com/blog/947191Spring MVC的确很强大,在每一个你想的到和想不到的地方都会留下钩子,来插入自定义的实现,透明替换默认实现,拦截器堆栈结构设计的非常强大,多种试图的解析,url mapping的多种实现,Locale resolver、Theme resolver、multipart file resolver,Excepiton hanlder Resolver等等,能让Spring MVC从1.0到3.0经历巨大变化,仍能向后兼容,并支持很酷的RESTful风格和强大的简化xml配置的注解。这些功能我们在项目中经常用到
阅读全文
摘要:无论做什么项目,进行异常处理都是非常有必要的,而且你不能把一些只有程序员才能看懂的错误代码抛给用户去看,所以这时候进行统一的异常处理,展现一个比较友好的错误页面就显得很有必要了。跟其他MVC框架一样,springMVC也有自己的异常处理机制。springMVC提供的异常处理主要有两种方式,一种是直接实现自己的HandlerExceptionResolver,另一种是使用注解的方式实现一个专门用于处理异常的Controller——ExceptionHandler。1、实现自己的HandlerExceptionResolver,HandlerExceptionResolver是一个接口,sprin
阅读全文
摘要:项目配置中加了 mvc:resources后 如下:Java代码<mvc:annotation-driven/><mvc:resourcesmapping="/webeditor/**"location="/webeditor/"/>@ResponseBody的ajax请求出现中文乱码解决的方式如下Java代码<!--<mvc:annotation-driven/><mvc:resourcesmapping="/webeditor/**"location="/webeditor
阅读全文
摘要:我们已经知道了ViewResolver的主要职责是,根据Controller所返回的ModelAndView中的逻辑视图名,为DispatcherServlet返回一个可用的View实例。现在是揭开ViewResolver如何“尽职”的时候了。有ViewResolver的职责为前提,理解甚至于自己声明一个ViewResolver接口变得不再困难。实际上ViewResolver接口定义确实很简单,如下所示:public interface ViewResolver { View resolveViewName(String viewName, Locale locale) throws Exce
阅读全文
浙公网安备 33010602011771号