🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` SpringData家族成员之一,用于操作MongoDb的持久层框架,封装了底层的mongodb-driver。 ``` ~~~ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> ~~~ ``` server: port: 9006 spring: application: name: project-name #指定服务名 data: mongodb: host: 192.168.184.134 database: dbname ``` ### dao ~~~ public interface MongoDao extends MongoRepository<Label, String> { } ~~~ ### Service ~~~ @Service public class MongoService { @Autowired private MongoDao mongoDao; @Autowired private IdWorker idWorker; public List<Label> findAll(){ return mongoDao.findAll(); } public Label findById(String id){ return mongoDao.findById(id).get(); } public void add(Label label){ label.setId(idWorker.nextId()+""); mongoDao.save(label); } public void update(Label label){ mongoDao.save(label); } public void deleteById(String id){ mongoDao.deleteById(id); } } ~~~