Use Leopard MVC and leopardmvc
Use Leopard MVC to learn how to use Leopard MVC.
This guide will guide you through the configuration of Leopard MVC.
How to complete this guide
You can start from scratch and complete each step, or you can bypass the basic setup steps you are already familiar. Either way, you can finally get the code that can work.
1. Configure maven dependency
Add pom. xml in the web module
<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. Configure 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. Use special parameters on the Leopard page
Createsrc/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. Compile 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. Run
Opensrc/test/java/io/leopard/site/JettyTest.java
Right-click Run As> Java Application and start Jetty test.
6. access through a browser
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"}
Summary
Congratulations! You can use Leopard MVC in the old project configuration. Although the function is simple, you can expand your business system on this basis. Good luck.