您的位置:首页 > 编程语言 > Java开发

[置顶] JAVA元数据编程零接触 -- 实现简单的MVC跳转控制雏形

2016-08-25 16:56 567 查看
之前自己写的FLEAMVC框架虽然实现了0配置的问题,但是在MVC的实现上问题颇多,最近看了下元数据编程.也理清了思路...

 

对于控制器 它不是自己调用的,而是由core核心来调用的 , 这里贴出一个刚刚写的雏形代码...

 

package cn.iamsese.www.webdev.annotation;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(value=RetentionPolicy.RUNTIME)
public @interface ToView {
public String url() default "http://iamsese.cn/index.do" ;
}

 

 

package cn.iamsese.www.webdev.annotation;

public class MC {

@ToView(url="http://iamsese.cn/iamsese.do")
public void listAction(){
System.out.println("操作list方法");
}

}

 

 

 

package cn.iamsese.www.webdev.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class Test {

public void interop(Method met){
Annotation[] ann = met.getAnnotations();
if (met.isAnnotationPresent(ToView.class)){
ToView annserv = (ToView)
met.getAnnotation(ToView.class);
String url = annserv.url();
String metname = met.getName();
System.out.println("[" + metname + "/" + url + "]");
}

}

public void _do(String ctr , String act) throws Exception{
Class <?> cls = Class.forName("cn.iamsese.www.webdev.annotation." + ctr) ;
Method met1 = cls.getMethod(act + "Action");
met1.invoke(cls.newInstance(), null);
this.interop(met1);
}
public static void main(String[] args) throws Exception {
(new Test())._do("MC", "list");
}
}

 

 



 

Spring 2.5似乎完成了这种功能,尚未接触,这里将所需文件上传至此,嘿嘿

 





大小: 23.8 KB

baseAnnotationIocOfSpring.rar (2.8 MB)

下载次数: 15

查看图片附件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: