Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JAVA annotationÈëÃÅ

JAVA annotationÈëÃÅ 
        ×î½ü¶ÔspringÔ´Âë¸ÐÐËȤ£¬½ñÌì¿´µ½annotation²¿·Ö£¬ÂÔ¼ÇÖ®¡£
Ò». ×î³£¼ûµÄannotation
@Override:ÓÃÔÚ·½·¨Ö®ÉÏ£¬ÓÃÀ´¸æËß±ðÈËÕâÒ»¸ö·½·¨ÊǸÄд¸¸ÀàµÄ
@Deprecated:½¨Òé±ðÈ˲»ÒªÊ¹ÓþɵÄAPIµÄʱºòÓõÄ,±àÒëµÄʱºò»áÓòúÉú¾¯¸æÐÅÏ¢,¿ÉÒÔÉ趨ÔÚ³ÌÐòÀïµÄËùÓеÄÔªËØÉÏ.
@SuppressWarnings:ÔÝʱ°ÑһЩ¾¯¸æÐÅÏ¢ÏûÏ¢¹Ø±Õ
@Entity:±íʾ¸ÃÀàÊǿɳ־û¯µÄÀà
 
¶þ. Éè¼ÆÒ»¸ö×Ô¼ºµÄAnnotation
      ÏÈ¿´´úÂëÔÙ½²»°
1. Ö»ÓÐÒ»¸ö²ÎÊýµÄAnnotationʵÏÖ
 
package chb.test.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MyAnnotation1 {
String value();

 
2. ÓÐÁ½¸ö²ÎÊýµÄAnnotationʵÏÖ
 
package chb.test.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MyAnnotation2 {
String description();
boolean isAnnotation();

 
3. AnnotationʵÑéÀà
 
package chb.test.annotation;
@MyAnnotation1("this is annotation1")
public class AnnotationDemo {
@MyAnnotation2(description="this is annotation2",isAnnotation=true)
public void sayHello(){
System.out.println("hello world!");
}

 
4.Annotation²âÊÔ˵Ã÷Àà
 
package chb.test.annotation;
import java.lang.reflect.Method;
import org.junit.Test;
public class TestAnnotation {
@Test
public void test() throws ClassNotFoundException, SecurityException, NoSuchMethodException{
Clas


Ïà¹ØÎĵµ£º

javaÐĵã¡

1.    Êý×éÓÐûÓÐlength()Õâ¸ö·½·¨? StringÓÐûÓÐlength()Õâ¸ö·½·¨£¿
        ´ð£ºÊý×éûÓÐlength()Õâ¸ö·½·¨£¬ÓÐlengthµÄÊôÐÔ¡£
        StringÓÐlength()Õâ¸ö·½·¨¡£
2.     String s = new String("xyz");´ ......

ÎҵĵÚÒ»¸öFreeMarkerÄ£°åÉú³Éjava´úÂëµÄÀý×Ó

µÚÒ»²½.н¨Ò»¸öÄ£°åÎļþÒÔ.ftl½áβ¡£
IDAO.ftl
 package com.media.dao;
import java.util.List;
import com.media.bean.${model_name};
import com.media.exceptions.DAOException;
/**
* ${model_name_cn}½Ó¿Ú
*
* @author ${author}
* @link ${link}
*
* @version $Revision: 1.00 $ $Date: ......

Java Reflection (JAVA·´Éä) Ïê½â

 
    JavaÓïÑÔ·´ÉäÌṩһÖÖ¶¯Ì¬Á´½Ó³ÌÐò×é¼þµÄ¶à¹¦ÄÜ·½·¨¡£ËüÔÊÐí³ÌÐò´´½¨ºÍ¿ØÖÆÈκÎÀàµÄ¶ÔÏó(¸ù¾Ý°²È«ÐÔÏÞÖÆ)£¬ÎÞÐèÌáǰӲ±àÂëÄ¿±êÀà¡£ÕâÐ©ÌØÐÔʹµÃ·´ÉäÌØ±ðÊÊÓÃÓÚ´´½¨ÒԷdz£ÆÕͨµÄ·½Ê½Óë¶ÔÏóЭ×÷µÄ¿â¡£ÀýÈ磬·´Éä¾­³£ÔÚ³ÖÐø´æ´¢¶ÔÏóΪÊý¾Ý¿â¡¢XML»òÆäËüÍⲿ¸ñʽµÄ¿ò¼ÜÖÐʹÓá£Java reflection ·Ç³£ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ