MongoTemplate 操作 mongodb
1. 增加依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> <version>1.5.2.RELEASE</version> </dependency>
2.增加配置
spring.data.mongodb.database=test spring.data.mongodb.uri=mongodb://user::27017/admin
6.测试
@Document(collection = "login_log") @Data public class LoginLog { @Id private String id; private String customerId; private String deviceId; private String deviceName; private long lastLoginTime; }
@Api(value = "MongodbController", description = "Test接口") @RestController @RequestMapping("/loginLog") @Slf4j public class MongodbController { @Autowired private MongoTemplate template; @ApiOperation(value = "用户登录日志", notes = "用户登录日志") @RequestMapping(value = "/list", method = RequestMethod.GET) public String list(String key) { Query query = new Query(); query.addCriteria(Criteria.where("customerId").is(Integer.parseInt(key))); List<ClientDevice> clientDevices = template.find(query, LoginLog.class); return clientDevices.toString(); } }
相关推荐
大秦铁骑 2020-08-19
thatway 2020-08-19
lovecodeblog 2020-08-19
lbyd0 2020-11-17
BigYellow 2020-11-16
sushuanglei 2020-11-12
我心似明月 2020-11-09
zhushenghan 2020-11-09
sunnnyduan 2020-10-16
不要皱眉 2020-10-14
xiaohai 2020-09-29
songxiugongwang 2020-09-22
萌亖 2020-09-17
LuckyLXG 2020-09-08
sdmzhu 2020-09-01
mkhhxxttxs 2020-09-16
xiaohai 2020-09-16
newcome 2020-09-09