论坛首页 Java企业应用论坛

基于spring3.0.5 mvc 简单用户管理实例

浏览 106916 次
该帖已经被评为精华帖
作者 正文
   发表时间:2011-06-09  
matychen 写道
太阳神喻 写道

首先,你为什么要这样写com.*.*.web.interceptor.BindingInitializer,你不能确定你的BindingInitializer具体路径?你的BindingInitializer是怎么写的啊?贴出来看一下,是用的spring自带的日期的属性编辑器还是自定义的?



public class BindingInitializer implements WebBindingInitializer {

	public void initBinder(WebDataBinder binder, WebRequest arg1) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(
				dateFormat, false));
	}

}


前面有公司名,不好写出来。所以用×号代替了。
不管是用自定义的还是spring自带的,都出现这个问题,我还发现,如果这个写在了最前面,会出现另外一个错误,直接登录页面都不能进入了。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" 
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
	
       <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="webBindingInitializer">
			<bean class="com.*.*.web.interceptor.BindingInitializer" />
		</property>
	</bean>

	<!-- 自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
	<context:component-scan base-package="com.*.*.web.*" />
	<!-- controller层的属性和配置文件读入 ,多个用逗号隔开-->
	<context:property-placeholder location="classpath:/config/others/config.properties" />
	<!-- Configures support for @Controllers -->
	<mvc:annotation-driven />

确定前台传过来的格式是正确的吗?跟一下看什么位置出了错。是有人说
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="com.*.*.web.interceptor.BindingInitializer" />
</property>
</bean>
要放在<mvc:annotation-driven />后面才可以。
0 请登录后投票
   发表时间:2011-06-09  
被人投了个隐藏,我违规了吗?
0 请登录后投票
   发表时间:2011-06-09  
登录时返回的登录提示信息乱码是怎么回事
0 请登录后投票
   发表时间:2011-06-09  
太阳神喻 写道

确定前台传过来的格式是正确的吗?跟一下看什么位置出了错。是有人说
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="com.*.*.web.interceptor.BindingInitializer" />
</property>
</bean>
要放在<mvc:annotation-driven />后面才可以。


前台是EXTJS post过来的值:
引用

dir DESC
endTime 2011-06-09 23:59:59
limit 10
msisdn
sort startTime
start 0
startTime 2011-06-01 00:00:00


放在了<mvc:annotation-driven />后面也不行呢,

我后来发现在需要转换的controll里面写入就可以了

@Controller
@RequestMapping("/record")
public class RecordController {

	@Autowired
	RecordService recordService;
	@InitBinder
    public void initBinder(WebDataBinder binder) {
        CustomDateEditor editor = new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true);
        binder.registerCustomEditor(Date.class, editor);
    }


还是不玩这个全局的玩意了。呵呵~~~
0 请登录后投票
   发表时间:2011-06-09  
数据库脚本呢?
0 请登录后投票
   发表时间:2011-06-09   最后修改:2011-06-09
river5566 写道
数据库脚本呢?

公司上网不方便,就简单两张表,几个字段,手动建一下就行了,或者把hibernate.hbm2ddl.auto设置为update,项目启动的时候会自动建表的
0 请登录后投票
   发表时间:2011-06-09  
tiger1102 写道
登录时返回的登录提示信息乱码是怎么回事

有乱码吗?还没注意呢
0 请登录后投票
   发表时间:2011-06-09  
没有乱码啊,你是不是没有设置转码?
0 请登录后投票
   发表时间:2011-06-09  
已搞定,不错,学习了

楼主辛苦了
0 请登录后投票
   发表时间:2011-06-09  
先感谢LZ分享。

在学习中发现几个问题,希望LZ及各位大侠能给予帮助。

源码是下来之后,根据LZ给的jar包截图导入,spring相关的都是3.0.5的,其他的可能会有一些不同。

继承HibernateDaoSupport时,会报错说:HibernateDaoSupport cannot be resolved to a type。

然后我查了一下,说是缺少spring.jar,我当时在spring3中没找到这个,然后添加了spring2.5中的这个jar,就不报错了。

但是还有几个import会报错:
1、org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
2、org.springframework.web.bind.WebDataBinder;
3、org.springframework.web.bind.support.WebBindingInitializer;
4、org.springframework.web.bind.annotation.RequestMapping;
5、org.springframework.web.servlet.ModelAndView;
6、org.apache.commons.lang.StringUtils;
7、org.springframework.web.bind.annotation.PathVariable;
8、org.springframework.web.bind.annotation.RequestMapping;
9、org.springframework.web.bind.annotation.RequestMethod;
10、org.springframework.web.bind.annotation.RequestParam;
还有一个是配置文件里的org.apache.commons.dbcp.BasicDataSource

仔细查了一下jar里面的内容,这个类都有,但不知道为什么不识别。

因为之前我整合过SSH,也被jar的问题困扰过,所以我就把之前项目的jar全部移植过来,没有报错。但是启动tomcat时又会报方法找不到的错:
java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlReaderContext.getRegistry();
但是我找了一下,存在这个方法啊。

难道还是jar包冲突的问题,往楼主解答。

0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics