日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring MVC-视图解析器(View Resolverr)-内部资源视图解析器(Internal Resource View Resolver)示例(转载实践)...

發布時間:2023/12/20 javascript 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring MVC-视图解析器(View Resolverr)-内部资源视图解析器(Internal Resource View Resolver)示例(转载实践)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以下內容翻譯自:https://www.tutorialspoint.com/springmvc/springmvc_internalresourceviewresolver.htm

說明:示例基于Spring MVC 4.1.6

InternalResourceViewResolver用于將提供的URI解析為實際的URI。以下示例顯示如何使用Spring Web MVC框架使用InternalResourceViewResolver。InternalResourceViewResolver允許使用請求映射網頁。

package com.tutorialspoint;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.ui.ModelMap;@Controller @RequestMapping("/hello") public class HelloController{@RequestMapping(method = RequestMethod.GET)public String printHello(ModelMap model) {model.addAttribute("message", "Hello Spring MVC Framework!");return "hello";}}

?

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/jsp/"/><property name="suffix" value=".jsp"/> </bean>

例如,使用上面的配置,如果是URI

  • /hello被請求,DispatcherServlet將請求轉發到前綴+ view-name + suffix = /WEB-INF/jsp/hello.jsp。

  • 首先,讓我們使用Eclipse IDE,并按照以下步驟使用Spring Web Framework開發基于動態窗體的Web應用程序:

    步驟描述
    1創建一個名為TestWeb的項目,在一個包com.tutorialspoint下,如Spring MVC - Hello World Example章節所述。
    2在com.tutorialspoint包下創建一個Java類HelloController。
    3在jsp子文件夾下創建一個視圖文件hello.jsp。
    4最后一步是創建所有源和配置文件的內容并導出應用程序,如下所述。

    HelloController.java

    package com.tutorialspoint;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.ui.ModelMap;@Controller @RequestMapping("/hello") public class HelloController{@RequestMapping(method = RequestMethod.GET)public String printHello(ModelMap model) {model.addAttribute("message", "Hello Spring MVC Framework!");return "hello";}}

    TestWeb-servlet.xml

    <beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"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-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:component-scan base-package="com.tutorialspoint" /><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/jsp/" /><property name="suffix" value=".jsp" /></bean></beans>

    hello.jsp

    <%@ page contentType="text/html; charset=UTF-8" %> <html> <head> <title>Hello World</title> </head> <body><h2>${message}</h2> </body> </html>?

    完成創建源文件和配置文件后,導出應用程序。右鍵單擊應用程序并使用Export > WAR File選項,并將您的TestWeb.war文件保存在Tomcat的webapps文件夾中。

    現在啟動您的Tomcat服務器,并確保您可以使用標準瀏覽器從webapps文件夾訪問其他網頁。現在嘗試訪問URL?http://localhost:8080/TestWeb/hello,如果您的Spring Web應用程序一切正常,您應該看到以下結果:

    Maven示例:

    https://github.com/easonjim/5_java_example/tree/master/springmvc/tutorialspoint/test1

    ?

    轉載于:https://www.cnblogs.com/EasonJim/p/7500027.html

    創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

    總結

    以上是生活随笔為你收集整理的Spring MVC-视图解析器(View Resolverr)-内部资源视图解析器(Internal Resource View Resolver)示例(转载实践)...的全部內容,希望文章能夠幫你解決所遇到的問題。

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