Jodd快速开发MVC - hello madvoc

转自:http://my.oschina.net/zqq90/blog/185144

 

摘要  使用Jodd-madvoc快速搭建MVC

 

Jodd Madvoc - hello madvoc

Jodd MVC 最简单实践

1. 准备Jar

  • jodd-3.4.8.jar
  • slf4j-api-1.7.5.jar
  • slf4j-simple-1.7.5.jar

如果使用 maven 只需在 pom.xml 中添加依赖

01 <dependency>
02     <groupId>org.jodd</groupId>
03     <artifactId>jodd-madvoc</artifactId>
04     <version>3.4.8</version>
05 </dependency>
06 <dependency>
07     <groupId>org.slf4j</groupId>
08     <artifactId>slf4j-api</artifactId>
09     <version>1.7.5</version>
10 </dependency>
11 <dependency>
12     <groupId>org.slf4j</groupId>
13     <artifactId>slf4j-simple</artifactId>
14     <version>1.7.5</version>
15 </dependency>

2. 添加madvoc的过滤器

文件: web.xml

1 <filter>
2     <filter-name>madvoc</filter-name>
3     <filter-class>jodd.madvoc.MadvocServletFilter</filter-class>
4 </filter>
5 <filter-mapping>
6     <filter-name>madvoc</filter-name>
7     <url-pattern>/*</url-pattern>
8 </filter-mapping>

3. 添加 Action

文件: webit/demo/madvoc/HelloAction.java

01 // Copyright...
02 package webit.demo.madvoc;
03  
04 import jodd.madvoc.meta.Action;
05 import jodd.madvoc.meta.MadvocAction;
06  
07 /**
08  *
09  * @author zqq90
10  */
11 @MadvocAction
12 public class HelloAction {
13  
14     @Action
15     public Object view() {
16         return "text:hello madvoc";
17     }
18 }

4. OK 完成,验收

启动 tomcat

1 [http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Madvoc starting...
2 [http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Default Madvoc web application created.
3 [http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Configuring Madvoc using defaultautomagic configurator
4 [http-apr-8080-exec-36] INFO jodd.madvoc.config.AutomagicMadvocConfigurator - Madvoc configured in 50 ms. Total actions: 1
5 [http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Madvoc is up and running.

浏览器打开 http://localhost:8080/ [部署的项目名字] /hello.html

1 hello madvoc

你可能感兴趣的:(快速开发)