小编Ani*_*nil的帖子

如何使用 MongoRepository 接口更新 mongo db 中的特定字段?

如何在 spring 中使用 MongoRepository 接口更新 mongo db 集合中的特定字段?

java spring mongorepository spring-mongodb

8
推荐指数
1
解决办法
2万
查看次数

我想忽略JSON中的字段只在少数情况下是否可能?

我的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)

}

我希望你明白我的观点

java spring json model spring-mvc

2
推荐指数
1
解决办法
500
查看次数