I created spring api for user they can use the oldpassword and company to get the new username and password. How can we select specific fields in Spring query creation?
I created repo like this:
@Repository
public interface UserRepository extends JpaRepository<User, String> {
List<User> findUserByCompanyAndOldUsername(String company, String oldUsername);
}
and I return the data of my row tables like this:
@GetMapping("/index")
public ResponseEntity<List<User>> getUserByCompanyAndOldUsername(@RequestParam String company,
@RequestParam String oldUsername){
return new ResponseEntity<>(userRepository.findUserByCompanyAndOldUsername(company, oldUsername), HttpStatus.OK);
}
and the result:
{
"id": 1,
"oldUsername": "FDIFSA00101",
"customerKey": "FRIFSA00101",
"company": "FRI",
"newUser": "FSA00101",
"oldPassword": "$2a$10$36dHjzxiEpvrjVPE6OhzkeiinNZt3/H7SjpKEI/LHqBAJ0MAZD6O2",
"newPassword": "Password"
}
I only need the newUser and newPassword data for me to display on the thymeleaf html page not the all data. how i can do that?
CodePudding user response:
Ignore the fields while deserializing to your dto. You can use:
@JsonIgnore
@JsonProperty(value = "field_name")
Use these annotations above the fields or before their getter methods for which you don't want to see any values in response. It should work.
Note: for camelCase names, follow this style: firstName
to first_name