日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

spring MVC(2)--注解Hello World

發布時間:2024/9/20 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring MVC(2)--注解Hello World 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

  • 定義Controller,增加注解@Controller

  • package?com.zte.controller2; import?org.springframework.stereotype.Controller; import?org.springframework.web.bind.annotation.RequestMapping; import?org.springframework.web.servlet.ModelAndView; /****?@author?WuBaoGui*/ @Controller public?class?HelloController {@RequestMapping(value="/hello1")public?ModelAndView?helloWorld(){//1、收集參數//2、綁定參數到命令對象//3、調用業務對象//4、選擇下一個頁面ModelAndView?mv?=?new?ModelAndView();//添加模型數據可以是任意的POJO對象mv.addObject("message",?"Hello?World!");//設置邏輯視圖名,視圖解析器會根據該名字解析到具體的視圖頁面mv.setViewName("hello");return?mv;} }


    ????2. XML增加如下配置

    <?xml?version="1.0"?encoding="UTF-8"?> <beans?xmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc"?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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"><!--????<bean?class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"?/>???????????<bean?class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"?/>-->???<bean?class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/><bean?class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/><!--?v3.1?<bean?class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"?/><bean?class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"?/>--><bean?class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property?name="viewClass"?value="org.springframework.web.servlet.view.JstlView"?/><property?name="prefix"?value="/WEB-INF/jsp/"?/><property?name="suffix"?value=".jsp"?/>?</bean><bean?name="/hello"?class="com.zte.controller.HelloController"/><!--?處理器--><bean?class="com.zte.controller2.HelloController"/> </beans>

    ? ? 3. 注冊Bean

    <bean?class="com.zte.controller2.HelloController"/>


    轉載于:https://my.oschina.net/looten/blog/305600

    總結

    以上是生活随笔為你收集整理的spring MVC(2)--注解Hello World的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。