我使用Spring Boot和Lombok编写了一些代码。我有两个对象,Zend\ServiceManager#getServiceLocator()
和user
都基于loggedInUser
。我为每个对象User.class
字段分配了不同的值。我得到了以下代码。 userEmail
是端点请求中的内容,而user
是执行请求的用户。
这是loggedInUser
:
User.class
这是我正在使用@Component
@Data
public class User {
private String userEmail;
}
User.class
return(new ResponseEntity(users,headers,HttpStatus.OK)); }
它给了我以下输出。
private User user;
private User loggedInUser;
private SearchParameters searchParameters;
public UserController(
User user,
User loggedInUser,
SearchParameters searchParameters, {
this.user = user;
this.loggedInUser = loggedInUser;
this.searchParameters = searchParameters;
}
@GetMapping(value = "${apiVersion.v_1}" + "/users")
public ResponseEntity getUsers(
@RequestParam("userEmail") String userEmail,
@RequestParam("direction") String direction,
@RequestParam("limit") String limit) {
Jws<Claims> jwsClaims = (Jws<Claims>) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
loggedInUser.setUserEmail(jwsClaims.getBody().getSubject()); //From a JWT the logged in user's e-mail is picked up. In this case joe@example.com
log.info("loggedInUser.getUserEmail #1: " + loggedInUser.getUserEmail());
user.setUserEmail(userEmail); // From the request parameters the email is that will be used for the search is picked up. In this case smith@example.com
searchParameters.setDirection(direction); //Can be "u" or "d" that corresponds to "SELECT * FROM user_tbl WHERE < user.getEmail()" or "SELECT * FROM user_tbl WHERE > user.getEmail()" in the SQL that will run in another class
searchParameters.setLimit(limit); //An integer that will limit the number of returned results from the user_tbl
log.info("loggedInUser.getUserEmail #2: " + loggedInUser.getUserEmail());
//The search is done in another class that is taking user.getEmail() as an argument and returns a List of users
我原以为loggedInUser.getUserEmail #1: joe@example.com
loggedInUser.getUserEmail #2: smith@example.com
和user
是两个独立的对象,因为它们有不同的名称,并且依赖注入每次实例化一个新对象,但似乎loggedInUser
是覆盖user
。我在这里缺少什么?