日期:2014-05-16 浏览次数:20508 次
@Service("myService") public class TestService { private Logger log = Logger.getLogger(getClass()); private MongoTemplate mongoTemplate; public List<User> findAll(String collectionName) { return mongoTemplate.findAll(User.class, collectionName); } public void save(String collectionName, List<User> items) { if (StringUtils.isNotEmpty(collectionName)) { mongoTemplate.dropCollection(collectionName); mongoTemplate.insert(items, collectionName); } else { log.error("name does not exist."); } } public void delete(String collectionName) { if (StringUtils.isNotEmpty(collectionName)) { mongoTemplate.dropCollection(collectionName); } else { log.error("name does not exist."); } } @Autowired public void setMongoTemplate(MongoTemplate mongoTemplate) { this.mongoTemplate = mongoTemplate; } }