我有反思的问题.我决定使用反射创建一个SQL查询生成器.我创建了自己的注释来确定可以使用哪些类,可以存储哪些属性等.代码按照我的意愿工作,但问题在于使用此项目作为其他人的依赖.
我有另一个使用OJDBC的项目,我试图使用我的库来生成基于类的查询.但是,当我从我的ojdbc项目传递一个类时,所有类信息都丢失了,该类显示为java.lang.Class,甚至注释信息也丢失了.有谁知道为什么会这样?
private static <T> void appendTableName(Class<T> cls) throws NotStorableException {
Storable storable = cls.getAnnotation(Storable.class);
String tableName = null;
if (storable != null) {
if ((tableName = storable.tableName()).isEmpty())
tableName = cls.getSimpleName();
} else {
throw new NotStorableException(
"The class you are trying to persist must declare the Storable annotaion");
}
createStatement.append(tableName.toUpperCase());
}
Run Code Online (Sandbox Code Playgroud)
在cls.getAnnotation(Storable.class)当下面的类传递给它正在失去信息
package com.fdm.ojdbc;
import com.fdm.QueryBuilder.annotations.PrimaryKey;
import com.fdm.QueryBuilder.annotations.Storable;
@Storable(tableName="ANIMALS")
public class Animal {
@PrimaryKey
private String name;
public String getName() {
return name;
}
public void setName(String …Run Code Online (Sandbox Code Playgroud)