标签:div ann runtime isa mongod list color ref csu
@Retention(RetentionPolicy.RUNTIME) public @interface MongodbTable { String name(); } public class AbstractMongoDao<T> { private Class<T> clazz; private String collectionName; @Autowired private MongoTemplate mongoTemplate; public AbstractMongoDao() { clazz = (Class<T>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]; if(clazz.isAnnotationPresent(MongodbTable.class)){ collectionName = clazz.getAnnotation(MongodbTable.class).name(); } } public void insert(T t){ mongoTemplate.insert(t, collectionName); } public List<T> findByPrefix(String rowKey){ Query query = Query.query(Criteria.where("rowKey").is(rowKey)); return mongoTemplate.find(query, clazz, collectionName); } }
标签:div ann runtime isa mongod list color ref csu
原文地址:https://www.cnblogs.com/exmyth/p/10765682.html