TinyFramework学习之HelloWorld工程以MVC方式建立

  1. 以maven-archetype-quickstart建立工程
  2. 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>




  3. 将新建的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
  4. 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);
    	}
    }
  5. 添加注解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>
  6. 添加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>






转载于:https://my.oschina.net/yygh/blog/516317

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值