本指南将引导您完成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测试
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,虽然功能比较简单,你可以在这个基础上扩展出你的业务系统,祝您好运。
新闻热点
疑难解答