每当我在控制器方法中使用RedirectAttributes时,如果我添加任何其他类似ModelMap或Model的东西,那么我就会收到以下错误。为什么呢?
我在网上检查了解决方案,但我没有找到任何东西。
java.lang.IllegalArgumentException:参数类型不匹配 sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)
弹簧servlet.xml中
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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/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.xsd">
<context:component-scan base-package="com.controller" />
<mvc:annotation-driven />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="username" value="system" />
<property name="password" value="system" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="userDAO" class="userDAO.UserDAOImpl"/>
<bean id="userService" class="userService.UserServiceImpl"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
//Controller class
@RequestMapping("/Check")
public String Check(@ModelAttribute("adduser") User user,ModelMap model,RedirectAttributes rd)
//This is my function
{
System.out.println(user.getUsername());
System.out.println(user.getPassword());
rd.addFlashAttribute("ajay", "Cjal");
model.addAttribute("Username",user.getUsername());
User result=userService.getByUserName(user.getUsername());
System.out.println(result);
if(result == null)
{
userService.addUser(user);
return "redirect:SuccessfulRegistration.html";
}
else
{
return "redirect:RegistrationError.html";
}
}
答案 0 :(得分:0)
您使用的是什么Spring版本?自Spring 3.1发布以来,已添加RedirectAttributes。请查看http://viralpatel.net/blogs/spring-mvc-flash-attribute-example/
上的示例