使用Leopard MVC

來源:互聯網
上載者:User

標籤:

使用Leopard MVC學習如何在使用Leopard MVC。

本指南將引導您完成Leopard MVC的配置。

How to complete this guide

你可以從頭開始並完成每一個步驟,或者您可以繞過你已經熟悉的基本設定步驟。無論哪種方式,你最終都可以得到可工作的代碼。

1、配置maven依賴

在web模組的pom.xml加入

    <dependencies>        [...]        <dependency>            <groupId>io.leopard</groupId>            <artifactId>leopard-test</artifactId>            <version>0.0.1-SNAPSHOT</version>        </dependency>        <dependency>            <groupId>io.leopard</groupId>            <artifactId>leopard-jetty</artifactId>            <version>0.0.1-SNAPSHOT</version>        </dependency>        <dependency>            <groupId>io.leopard</groupId>            <artifactId>leopard-web</artifactId>            <version>0.0.1-SNAPSHOT</version>        </dependency>        [...]    </dependencies>    <repositories>        <repository>            <id>leopard-snapshots</id>            <name>Leopard Snapshots</name>            <url>http://leopard.io/nexus/content/repositories/snapshots/</url>        </repository>    </repositories>
2、配置web.xml
<context-param>        <param-name>contextConfigLocation</param-name>        <param-value>            classpath:/leopard-web/applicationContext.xml        </param-value>    </context-param>    <context-param>        <param-name>contextClass</param-name>        <param-value>io.leopard.web.LeopardXmlWebApplicationContext</param-value>    </context-param>    <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>    <servlet>        <servlet-name>web</servlet-name>        <servlet-class>io.leopard.web.mvc.LeopardDispatcherServlet</servlet-class>        <init-param>            <param-name>contextConfigLocation</param-name>            <param-value>/WEB-INF/web-servlet.xml</param-value>        </init-param>        <load-on-startup>1</load-on-startup>    </servlet>    <servlet-mapping>        <servlet-name>web</servlet-name>        <url-pattern>/</url-pattern>    </servlet-mapping>
3、使用Leopard頁面特殊參數

建立src/main/java/io/leopard/site/web/controller/ParameterController.java

package io.leopard.site.web.controller;import io.leopard.web4j.view.JsonView;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic class ParameterController {@RequestMappingpublic JsonView userAgent(String userAgent) {return new JsonView("userAgent:" + userAgent);}@RequestMappingpublic JsonView sessUid(long sessUid) {return new JsonView("sessUid:" + sessUid);}}
4、編寫JettyTest

src/test/java/io/leopard/site/JettyTest.java

package io.leopard.site;import io.leopard.jetty.JettyServer;import org.junit.Ignore;@Ignorepublic class JettyTest {public static void main(String[] args) throws Exception {JettyServer.start();}}
5、運行

開啟src/test/java/io/leopard/site/JettyTest.java,右鍵菜單Run As -> Java Application啟動Jetty測試

6、使用瀏覽器訪問

http://localhost/parameter.do?format=true

{  "status" : "200",  "message" : "",  "data" : "userAgent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"}
總結

恭喜你!您已經可以在舊項目配置使用Leopard MVC,雖然功能比較簡單,你可以在這個基礎上擴充出你的業務系統,祝您好運。

使用Leopard MVC

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.