- 以maven-archetype-quickstart建立工程
- pom添加依赖:org.tinygroup.service;org.tinygroup.weblayer
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.qiyi</groupId> <artifactId>hellomvc</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>hellomvc</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.tinygroup</groupId> <artifactId>org.tinygroup.service</artifactId> <version>2.0.25</version> </dependency> <dependency> <groupId>org.tinygroup</groupId> <artifactId>org.tinygroup.weblayer</artifactId> <version>2.0.25</version> </dependency> </dependencies> </project>
- 将新建的hellomvc工程加入Web应用主工程的依赖下
1)application.xml加入jar包名前缀<include-patterns> <include-pattern pattern="org\.tinygroup\.(.)*\.jar"/> <include-pattern pattern="jstl-1.2.jar"/> <include-pattern pattern="com\.qiyi\.(.)*\.jar"/> </include-patterns>
2)Web应用主工程maven增加hellomvc工程的依赖
<dependency> <groupId>com.qiyi</groupId> <artifactId>hellomvc</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>
3)Web应用主工程布局文件default.layout添加调用url的入口html
Hellomvc示例:<a href="${TINY_CONTEXT_PATH}/hellomvc/mvc.page">Hellomvc方式</a><br/>
注意:现在Web应用主工程save会报错,需要等hellomvc工程完成后才OK
- Hellomvc工程添加Action
package com.qiyi.hellomvc.action; import org.tinygroup.weblayer.mvc.annotation.Controller; import org.tinygroup.weblayer.mvc.annotation.RequestMapping; import org.tinygroup.weblayer.mvc.annotation.ResultKey; import org.tinygroup.weblayer.mvc.annotation.View; @Controller() public class HellomvcAction { @RequestMapping(value={"/hellomvc.do"}) @View(value="/hellomvc/result.page") @ResultKey(value="result") public String sayHelloMethod(String name) { if (name == null) { name = "world"; } return String.format("Hello, %s", name); } }
- 添加注解xml
<?xml version="1.0" encoding="UTF-8"?> <annotation-class-matchers> <annotation-class-matcher class-name="(.)*Action" annotation-type="org\.tinygroup\.weblayer\.mvc\.annotation\.Controller"> <processor-beans> <processor-bean enable="true" name="controllerAnnotationAction"></processor-bean> </processor-beans> <!-- 规范类名必须是Action结尾的,业务方法必须是Method结尾的,加载器才会加载对应的annotation类型 --> <annotation-method-matchers> <annotation-method-matcher method-name="(.)*Method" annotation-type="org\.tinygroup\.weblayer\.mvc\.annotation\.RequestMapping"> <processor-beans> <processor-bean enable="true" name="controllerAnnotationAction"></processor-bean> </processor-beans> </annotation-method-matcher> </annotation-method-matchers> </annotation-class-matcher> </annotation-class-matchers>
- 添加bean定义xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="hellomvcAction" name="hellomvcAction" scope="prototype" class="com.qiyi.hellomvc.action.HellomvcAction"> </bean> </beans>
时间: 2024-10-12 07:36:33