0

私はSpringを初めて使用し、ダミーの銀行取引プロジェクトを開発しています。これまで、入金または出金ができるページにリンクするウェルカムページを作成しました。データベースとすべてが正常に機能します。そして、4つの属性(id、name、acctNo、balance)を持つ顧客のリストを示すテーブルがあります。IDは、この顧客に関する情報のみを表示したい次のページにリンクされています。どうすればこれを達成できますか。

Dispatcher-Servlet.xmlは次のとおりです。

<?xml version="1.0" encoding="UTF-8"?>
<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-2.5.xsd" 
    xmlns:p="http://www.springframework.org/schema/p">      
     <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix">
            <value>/WEB-INF/jsp/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
    <bean id="urlMapping"
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="interceptors">
            <list>
                <ref local="localeChangeInterceptor"/>
            </list>
        </property>
        <property name="urlMap">
            <map>              
                <entry key="/login.html">
                    <ref bean="userloginController"/>
                </entry>
            </map>          
        </property>             
    </bean>


   <!-- I tried adding this bean but noe luck, not sure where to use this id to map this bean -->
     <bean id="showindividualCustomer" class="com.showCustomerController">s
        <property name="successView"> <value>ViewCustomer</value></property>
     </bean>

     <bean id="userloginController" class="com.UserLoginFormController">
        <property name="sessionForm"><value>false</value></property>
        <property name="commandName"><value>userLogin</value></property>
        <property name="commandClass"><value>com.UserLogin</value></property>
        <property name="formView"><value>userLogin</value></property>
        <property name="successView"><value>showCustomer</value></property>
    </bean>

    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="hl"/>
    </bean> 
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>      
</beans>

そして、bean=showindividualcustomerのコントローラーは次のとおりです。

public class showCustomerController extends SimpleFormController{

    protected ModelAndView onSubmit(Object obj) throws ServletException{

        return new ModelAndView("ViewCustomer");//name of the jsp page inside WEB-INF/jsp
    }
}

ありがとうございました!!!

4

1 に答える 1

2

私は実際にSpring 3を最大限に活用することをお勧めします。コードを見て、Spring 2チュートリアルを見ていると思います。

spring 2.5.6 または spring 3.* を使用すると、次のことができます。

    @RequestMapping(value="/customer/{id}")
    public String showCustomerInformation(@PathVariable String id, HttpServletRequest request){
        //your logic to get the customer information and pass it on
        return "customerInformation";
    }

参考文献: http://tech-read.com/2011/10/31/spring-3-mvc-annotations/ http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference /html/mvc.html#mvc-ann-requestparam

編集: メソッドの署名を次のように変更します。

onSubmit(HttpServletRequest request, Object command) throws ServletException

そして、次を使用してください:

request.getParameter("id")
于 2013-02-10T21:32:28.310 に答える