<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> //还有一个依赖,官方demo里加的有,这个应该是启动的时候帮你下载mongodb数据库的,反正我是没有成功下载下来过,一直timeout,如果系统上装的有mongodb了,就不用要这个依赖了 <dependency> <groupId>de.flapdoodle.embed</groupId> <artifactId>de.flapdoodle.embed.mongo</artifactId> </dependency>
import org.springframework.data.annotation.Id;
public class User {
@Id
private String id;
private String username;
// getter, setter
}
spring: freemarker: template-loader-path: - file:./templates data: mongodb: database: dbname #一般只用配置这一个就可以了,如果数据库有密码,还要配置下面几个配置 host: password: uri:
public interface UserRepository extends MongoRepository<User, String> {
User findByUsername(String username);
}
{
"_id" : ObjectId("59cb127b23d8213c8dfdcad9"),
"_class" : "com.example.module.blog.model.Blog",
"title" : "hello world",
"content" : "hello world",
"inTime" : ISODate("2017-09-27T02:52:43.713+0000"),
"user" : {
"_id" : ObjectId("59cb0fec23d8213930c6795a"),
"username" : "tomoya",
"inTime" : ISODate("2017-09-27T02:41:48.402+0000")
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有