当前位置: 首页 > news >正文

获取注解信息

反射注解操作

getAnnotations
getAnnotation

ORM

image

练习ORM

package com.guo.reflection;import java.lang.annotation.*;
import java.lang.reflect.Field;//联系反射操作注解
public class Test12 {public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {Class c1 = Class.forName("com.guo.reflection.Student2");//通过反射获取注解Annotation[] annotations = c1.getAnnotations();for (Annotation annotation : annotations) {System.out.println(annotation);}System.out.println("============================");//获得注解的value的值Tableguo tableguo = (Tableguo) c1.getAnnotation(Tableguo.class);String value = tableguo.value();System.out.println(value);System.out.println("============================");//获得类指定的注解Field f = c1.getDeclaredField("id");Filedguo annotation = f.getAnnotation(Filedguo.class);System.out.println(annotation.columnName());System.out.println(annotation.type());System.out.println(annotation.length());System.out.println("============================");f = c1.getDeclaredField("age");annotation = f.getAnnotation(Filedguo.class);System.out.println(annotation.columnName());System.out.println(annotation.type());System.out.println(annotation.length());System.out.println("============================");f = c1.getDeclaredField("name");annotation = f.getAnnotation(Filedguo.class);System.out.println(annotation.columnName());System.out.println(annotation.type());System.out.println(annotation.length());System.out.println("============================");}
}@Tableguo("db-student")
class Student2{@Filedguo(columnName = "db_id",type = "int",length = 10)private int id;@Filedguo(columnName = "db_age",type = "int",length = 10)private int age;@Filedguo(columnName = "db_name",type = "varchar",length = 3)private String name;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;}@Overridepublic String toString() {return "Student2{" +"id=" + id +", age=" + age +", name='" + name + '\'' +'}';}
}//类名的注解
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface Tableguo{String value();
}//属性的注解
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@interface Filedguo{String columnName();String type();int length();
}
http://www.jsqmd.com/news/593279/

相关文章:

  • 解锁Koikatu全部潜能的6个专业步骤:KK-HF Patch增强指南
  • ai赋能:让快马智能生成优化与测试完备的c语言排序算法库
  • 第29课:先把屏幕做得愿意被触摸,用 Qt 图形演示点亮应用感
  • MySQL 很实用的 SQL 语句清单(排障与日常运维)
  • 基于Matlab Simulink平台的柔性直流输电系统研究与优化:四端网络模型与四端换流器控...
  • 京东抢购自动化:用Python脚本实现毫秒级响应的高效抢购方案
  • 5分钟免费指南:如何将旧手机变成Linux高清摄像头
  • MySQL 常用业务 SQL
  • 用Python模拟随机游走:从一维到三维,直观理解马尔可夫链的常返性
  • 构建现代化电商平台:SpringBoot后端与Vue前端的全栈实践指南
  • Sub-Agent 与 Agent Team 的本质区别
  • 5分钟搞定抖音音频提取:免费高效的douyin-downloader终极指南
  • AI for Science:化学生物学革命,从药物设计到蛋白质工程的全面解析
  • 电动汽车电动真空助力制动系统模型:一场制动系统的静默革命
  • 终极音乐解析方案:music-api如何免费打通四大平台音频资源壁垒
  • Maven项目引入本地JAR包的三种正确方式对比
  • YimMenu终极指南:GTA5安全增强与功能定制完全教程
  • claw-code 源码详细分析:`reference_data` JSON 快照——大型移植里「对照底稿」该怎么治理与演进?
  • PowerToys Image Resizer:三步解决全场景图片批量处理难题
  • 如何快速配置MangoHud快捷键:从零开始的游戏性能监控终极指南
  • AtCoder Beginner Contest 452(ABC452)
  • AI for Science新浪潮:化学合成规划,从算法原理到产业落地全解析
  • S7-1200 PLC 高级语言SCL数控G代码功能块源文件解析及程序思路
  • 新手友好:通过快马生成的代码项目理解智能车感知与控制基础
  • 基于碳排放交易与需求响应的综合优化调度策略:微网虚拟电厂日前调度模型研究
  • 从Kaggle到落地:Albumentations在医学影像分割和目标检测中的实战配置指南
  • 手把手教你用王思鱼指纹浏览器(Windows版)绕过主流检测站点
  • Hugging Face 快速入门手册(基础应用)
  • Boss-Key老板键:一键隐藏窗口的终极隐私保护神器
  • 云服务器环境配置怎么操作?云服务器环境搭建详细教程