如何在 spring 中使用 MongoRepository 接口更新 mongo db 集合中的特定字段?
我的ModelClass
public class UserPojo{
private String userEmailId;
private String userPassword;
private String userContactNumber;
//setters and getters
}
Run Code Online (Sandbox Code Playgroud)
我想将UserPojo类对象作为json发送,但在某些情况下,我希望使用userpassword发送,有些情况下没有userpassword可能会发送吗?
在下面的方法中,我想发送没有userpassword的userPojo对象.我的Spring版本是4.3.1.RELEASE.我有杰克逊图书馆
@RestController
@RequestMapping("/user")
public class UserController{
@GetMapping(value="/{userId}")
public UserPojo getUser(@PathVariable("userId") String userId){
//code goes here
//finally returning UserPojo Object
return userPojo;
}
}
Run Code Online (Sandbox Code Playgroud)
在下面的方法中我想用密码发送userPojo对象
@RestController
@RequestMapping("/admin")
public class AdminController{
@GetMapping(value="/{userId}")
public UserPojo getUser(@PathVariable("userId") String userId){
//code goes here
//finally returning UserPojo Object
return userPojo;
}
Run Code Online (Sandbox Code Playgroud)
}
我希望你明白我的观点