英文:
How to create custom annotation for StoredProcedure and Column in spring boot project?
问题
我需要为StoredProcedure和Column创建自定义注释。
示例:
@StoredProcedure带有三个参数,如query、structname、structArrayName
@Column有五个字段,如name、position、type、required。
有人可以帮我学习如何创建这些注释并应用于实体类吗?
英文:
I need to creat custom annotations for StoredProcedure & Column.
Example:
@StoredProcedure with three parameters like query,structname,structArrayName
and @Column with have five fields like name, postion, type, required.
Can anybody help me how create it and apply in entity class?
答案1
得分: -1
我们可以添加元注解来指定自定义注解的作用范围和目标。例如:
@Retention(RUNTIME)
@Target(TYPE)
public @interface StoredProcedure {
String query ();
String structName ();
String structArrayName ();
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Column {
public String name();
public int position ();
public String datePattern () default "MM/dd/yyyy HH:mm:ss.SSSSSS";
public String defValue () default "";
public boolean required () default false;
public String actualType () default "na";
}
// 我们可以在类级别和字段级别应用注解。
@StoredProcedure(query = "{}", structName = "", structArrayName = "")
public class Data {
@Column(name = "id", position = 1, actualType = "string", required = true)
@Validate(length = )
public String id;
@Column(name = "name", position = 2, actualType = "number")
@Validate(length = )
public Long name;
}
英文:
We can add meta-annotations to specify the scope and the target of our custom annotation.
Ex:
@Retention(RUNTIME)
@Target(TYPE)
public @interface StoredProcedure {
String query ();
String structName ();
String structArrayName ();
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Column {
public String name();
public int position ();
public String datePattern () default "MM/dd/yyyy HH:mm:ss.SSSSSS";
public String defValue () default "";
public boolean required () default false;
public String actualType () default "na";
}
// we can apply annotations in class level and field level.
@StoredProcedure(query = "{}", structName = "", structArrayName = "")
public class Data {
@Column(name = "id", position = 1, actualType = "string", required = true)
@Validate(length = )
public String id;
@Column(name = "name", position = 2, actualType = "number")
@Validate(length = )
public Long name;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论