springboot+mongodb
1.pom文件引入mongodb依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
2.配置文件(application.properties)配置mongodb的数据库信息
#mogodb配置
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=test
3.创建dto,service,dao,controller类
dto:
public String id;
public String name;
dao:
public interface CustomerRepository extends MongoRepository<Customer, String> {
public Customer findByFirstName(String name);
public List<Customer> findByLastName(String name);
}
controller:
@RequestMapping(value = "/getId")
public String getId(HttpServletRequest req, HttpServletResponse resp) {
Customer customer=new Customer("aaa");
return customerRepository.save(customer).getId();
}
相关文章
- 微服务技术系列教程(46)-SpringBoot整合MongoDB(文章评论案例)
- 微服务技术系列教程(11) - SpringBoot - 性能优化
- SpringBoot知识点整理
- springboot文件下载功能开发!
- 【MongoDB】从入门到精通mongdb系列学习宝典,想学mongodb小伙伴请进来
- SpringBoot 项目获取小程序openid 解决方案
- springboot集成mongoDB需要认证
- SpringBoot整合MybatisPlus3.X之分页插件(四)
- SpringBoot进阶-Redis数据类型及应用场景(四)
- 《SpringBoot篇》01.Springboot超详细入门(基础篇)
- Ecplise中Maven构建的springboot项目上有个红叉,运行正常启动并不报错
- SpringBoot中使用Spring profile进行配置【谨慎使用,参见SpringBoot 2.4.0发布文档】
- SpringBoot 整合 MongoDB 实现数据的增删改查!
- springboot mybatis自定义枚举enum转换
- springboot jpa mongodb 整合mysql Field in required a bean of type that could not be found Failed to load ApplicationContext
- springboot+rocketmq(3):实现广播消息
- 【MongoDB】在Mongodb使用shell实现与javascript的动态交互
- Springboot注解以及黑马学习资料
- SpringBoot多个环境配置文件
- springboot整合webservice