执行POST
请求时,密码必须以散列形式存储在数据库中。怎么做?这是我自己POST
:
@PostMapping("api/names/users")
public ResponseEntity<?> createPerson(@RequestBody Person newPerson) {
logger.info("Success_Post");
return new ResponseEntity<Person>(personRepository.save(newPerson), HttpStatus.OK);
这是课程Person
:
public class Person {
@Id
private String id;
private String name;
private String email;
private String password;
private String old;
(geters and setters)
事实证明,这很容易做到。您只需要添加
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
. 然后使用BCryptPasswordEncoder
. 一般来说,它看起来像这样: