Jodd MVC 最简单实践
1. 准备Jar
- jodd-3.4.8.jar
- slf4j-api-1.7.5.jar
- slf4j-simple-1.7.5.jar
如果使用 maven 只需在 pom.xml 中添加依赖
<dependency> <groupId>org.jodd</groupId> <artifactId>jodd-madvoc</artifactId> <version>3.4.8</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.5</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.5</version> </dependency>
2. 添加madvoc的过滤器
文件: web.xml
<filter> <filter-name>madvoc</filter-name> <filter-class>jodd.madvoc.MadvocServletFilter</filter-class> </filter> <filter-mapping> <filter-name>madvoc</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
3. 添加 Action
文件: webit/demo/madvoc/HelloAction.java
// Copyright...
package webit.demo.madvoc;
import jodd.madvoc.meta.Action;
import jodd.madvoc.meta.MadvocAction;
/**
*
* @author zqq90
*/
@MadvocAction
public class HelloAction {
@Action
public Object view() {
return "text:hello madvoc";
}
}
4. OK 完成,验收
启动 tomcat
[http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Madvoc starting...
[http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Default Madvoc web application created.
[http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Configuring Madvoc using default automagic configurator
[http-apr-8080-exec-36] INFO jodd.madvoc.config.AutomagicMadvocConfigurator - Madvoc configured in 50 ms. Total actions: 1
[http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Madvoc is up and running.
[http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Default Madvoc web application created.
[http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Configuring Madvoc using default automagic configurator
[http-apr-8080-exec-36] INFO jodd.madvoc.config.AutomagicMadvocConfigurator - Madvoc configured in 50 ms. Total actions: 1
[http-apr-8080-exec-36] INFO jodd.madvoc.Madvoc - Madvoc is up and running.
浏览器打开 http://localhost:8080/ [部署的项目名字] /hello.html
hello madvoc