当前位置:网站首页>Reflection operation annotation
Reflection operation annotation
2022-06-22 06:17:00 【Kuxiaoya】
practice :ORM( Object relation mapping )

The code is as follows :
/** * Practice reflection operation notes */
public class Demo12 {
public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
Class c1 = Class.forName("www.jin.Student2");
// Provide reflection to get annotation
Annotation[] annotations = c1.getAnnotations();
for (Annotation annotation : annotations) {
System.out.println(annotation);
}
// Get annotated value Value
TableJin tableJin = (TableJin) c1.getAnnotation(TableJin.class);
String value = tableJin.value();
System.out.println(value);
// Get the annotation specified by the class
Field f = c1.getDeclaredField("id");
FieldJin annotation = f.getAnnotation(FieldJin.class);
System.out.println(annotation.columnName());
System.out.println(annotation.type());
System.out.println(annotation.length());
}
}
@TableJin("db_student")
class Student2{
@FieldJin(columnName = "db_id",type = "int",length = 10)
private int id;
@FieldJin(columnName = "db_age",type = "int",length = 10)
private int age;
@FieldJin(columnName = "db_name",type = "varchar",length = 3)
private String name;
public Student2() {
}
public Student2(int id, int age, String name) {
this.id = id;
this.age = age;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Student2{" +
"id=" + id +
", age=" + age +
", name='" + name + '\'' +
'}';
}
}
// Annotation of class name
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface TableJin{
String value();
}
// Comment for attribute
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@interface FieldJin{
String columnName();
String type();
int length();
}
Running results :

边栏推荐
- 小熊派BearPi-HM Micro正式合入OpenHarmony主干
- Logback custom pattern parameter resolution
- 【Rust笔记】01-基本类型
- On the definition of jinja2 macro
- SQLServer中的子查询
- clickhouse对比两台机器数据
- Empirical mode decomposition (EMD) and Hilbert Huang transform (HHT)
- 五大常考SQL面试题
- Upload file prompt 413 request entity too large error
- e.hash & oldCap == 0 详细解读
猜你喜欢

Usage of trim, ltrim and rtrim functions of Oracle

从入门到精通之专家系统CLIPS(一)CLIPS初识与概述

Huiding technology gr551x series development board supports openharmony

【CPU设计实战】数字逻辑电路设计基础(一)

Little bear school bearpi HM micro officially integrated into openharmony trunk
![[NAND file system] UBI introduction](/img/69/7213b8b39cebc1626eb6bb8cc10d16.png)
[NAND file system] UBI introduction

No business series 7: removing spots from old photos

单细胞论文记录(part12)--Unsupervised Spatial Embedded Deep Representation of Spatial Transcriptomics

基于卫星测深的牙买加沿岸水深测量

博客添加邮箱私信 快捷
随机推荐
Detailed interpretation of tab[i = (n - 1) & hash]
SQL injection vulnerability (XIII) Base64 injection
单细胞论文记录(part11)--ClusterMap for multi-scale clustering analysis of spatial gene expression
reduce_ Reduction in sum()_ indices
为什么我选择 Rust
信息系统项目管理 - 范围管理(划重点)
ForkJoinPool
Inserting a classdiagram into markdown
idea本地运行scope
生信可视化(part3)--小提琴图
Shengxin visualization (Part3) -- violin diagram
基于卫星测深的牙买加沿岸水深测量
R language observation log (part24) -- writexl package
MySQL-IFNULL处理N/A
CGIC文件上传----菜鸟笔记
小熊派BearPi-HM Micro正式合入OpenHarmony主干
Shengxin visualization (Part1) -- histogram
【NAND文件系统】UBIFS介绍
Ptrade trading program code - from zero to firm offer 19
四大函数式接口(必需掌握)