springboot中简单使用mongodb
学习用,资料借鉴于spring官方文档,经过本人修改
创建工程
在创建工程时,添加SpringDataMongodb
实体类
@Document(collection = "user")
public class User implements Serializable {
@Id
private String id;
@Field("username")
private String username;
@Field("password")
private String password;
CURD
public User loginCheck(String username, String password){
User user = null;
//查询是否存在
Query query = new Query();
query.addCriteria(Criteria.where("username").is(username));
query.addCriteria(Criteria.where("password").is(password));
user = mongoTemplate.findOne(query, User.class);
return user;
}
public User insertUser(User user){