2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

Spring 3.x MVC 入門3-1 -- 使用內(nèi)容協(xié)商來實現(xiàn)多視圖 示例

 老鼠愛上美貓 2012-08-09

使用內(nèi)容協(xié)商實現(xiàn)多視圖例

根據(jù)前篇文件的介紹,這里直接給出例子

 

配置xml

<context:component-scan base-package="com.controls" />

   

    <context:annotation-config />

   

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">

        <property name="order" value="1" />

        <property name="favorParameter" value="false" />

        <property name="ignoreAcceptHeader" value="true" />

       

        <property name="mediaTypes">

            <map>

                <entry key="json" value="application/json" />

                <entry key="xml" value="application/xml" />        

            </map>

        </property>

       

        <property name="defaultViews">

            <list>

                <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"></bean>

                <bean class="org.springframework.web.servlet.view.xml.MarshallingView">

                    <constructor-arg>

                        <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">

                             <property name="classesToBeBound">

                                <list>

                                   <value>com.model.User</value>

                                </list>

                             </property>

                        </bean>

                    </constructor-arg>

                </bean>

            </list>

        </property>

    </bean>

    <!-- 上面沒匹配到則會使用這個視圖解析器 -->

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="order" value="2" />

        <property name="prefix" value="/WEB-INF/views/" />

        <property name="suffix" value=".jsp" />

        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />

    </bean>

 

 

Model

 

@XmlRootElement

public class User {

   

    private long userID;

    private String userName;

    private Date birth;

 

    public String getUserName() {

       return userName;

    }

    public void setUserName(String userName) {

       this.userName = userName;

    }

    public Date getBirth() {

       return birth;

    }

    public void setBirth(Date birth) {

       this.birth = birth;

    }

    public long getUserID() {

       return userID;

    }

    public void setUserID(long userID) {

       this.userID = userID;

    }

}

 

 

 

 

Contoller

@RequestMapping(value="/user/{userid}")

public String queryUser(@PathVariable("userid") long userID, ModelMap model)

{

      

       User u = new User();

       u.setUserID(userID);

       u.setUserName("zhaoyang");

       model.addAttribute("User", u);

      

       return "User";

}

 

 

如果是返回text/html,還需要建立個jsp文件

<body>

    UserName: ${requestScope.User.userID } <br />

    Age: ${requestScope.User.userName }

  </body>

 

測試結(jié)果

json

 

xml

 

 

 

jsp

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多