首页 > 解决方案 > 从 DTO 映射到实体时如何对密码进行编码?

问题描述

在 Spring Boot App 中,我想UserDTO使用 Orika Mapper 将一个简单的(登录、密码)映射到一个用户实体。我不知道如何PasswordEncoder.encode在映射时对密码调用方法进行编码。我应该使用不同的映射器吗?

标签: javaspring-bootorika

解决方案


在映射到实体之前,您可以使用 Spring5 的默认编码器,其工作原理如下

  @Override
    protected void configure(AuthenticationManagerBuilder auth) 
      throws Exception {
        auth.inMemoryAuthentication()
          .withUser("user")
          .password("password")
          .roles("USER");
    }

有关更多详细信息,您可以在此处查看https://www.baeldung.com/spring-security-5-default-password-encoder


推荐阅读