Ruby 语言 思想驱动生活

July 8, 2010

spring里的ModelAttribute

Filed under: 技术 — liubin @ 15:42

在spring里,model和form的对应不需要写xml文件,只需要在页面里用form这个taglib就可以了:

email

这里的commandName就是和Controller里相互映射的model的名字(实例名)
path=email指定了对应对象的属性。

Controller里可以这样写:
protected ModelAndView sendInvite(@ModelAttribute(“invite”) Invite invite,
BindingResult result, SessionStatus status, ModelMap model) {}

其中,参数的第一个invite会自动从form里生成一个Invite的实例并设置值,Controller里直接使用这个对象就可以。

而加上@SessionAttributes的话,可以在form里一直显示上次输入的form内容,直到自己调用status.setComplete()为止,这个操作的意思就是一个form相关联的操作已经结束,从session里清空就可以了

July 1, 2010

svn不能提交的错误

Filed under: 技术 — Tags: , , — liubin @ 16:25

Eclipse里提交代码的时候,提示:
org.tigris.subversion.javahl.ClientException: APR does not understand this error code
svn: Commit failed (details follow):
svn: Cannot accept non-LF line endings in ‘svn:log’ property

comment写了2行而已,查了下,网上有人说每行最后以空格结尾就行了,我试了下还是不行。

不要comment,提交成功。。。奇怪。

在spring中设置request的charset为utf-8

Filed under: 技术 — Tags: , , , , — liubin @ 14:48

在java里可以用:request.setCharacterEncoding(“UTF-8″);

在Spring的Controller类里个别设置太麻烦,可以用filter

  1. <filter-name>Spring character encoding filter</filter-name>
  2.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  3.         <init-param>
  4.             <param-name>encoding</param-name>
  5.             <param-value>utf-8</param-value>
  6.         </init-param>
  7.     </filter>
  8.     <filter-mapping>
  9.         <filter-name>Spring character encoding filter</filter-name>
  10.         <url-pattern>/*</url-pattern>
  11.     </filter-mapping>

Powered by WordPress