如何在 Spring Boot 中使用推土机? [英] How to use Dozer with Spring Boot?

查看:33
本文介绍了如何在 Spring Boot 中使用推土机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个 Spring Boot 项目.我只有注释配置.我想包括推土机来将实体转换为 DTO,将 DTO 转换为实体.我在推土机网站上看到,他们解释说我必须在 spring xml 配置文件中添加以下配置.由于我没有 xml 文件而是注释配置 Java 类,因此我不知道如何将其转换为 Java 配置类.

I am working on a Spring Boot project. I just have annotation configuration. I want to include dozer to transform Entities to DTO and DTO to Entities. I see in the dozer website, they explain i have to add the following configuration in spring xml configuration file. Since i have not xml file but annotation configuration Java class, i don't know how to translate this into Java Configuration class.

<bean id="org.dozer.Mapper" class="org.dozer.DozerBeanMapper">
  <property name="mappingFiles">
    <list>
      <value>dozer-global-configuration.xml</value>
      <value>dozer-bean-mappings.xml</value>
      <value>more-dozer-bean-mappings.xml</value>
    </list>
  </property>
</bean>

如果有人能给我一个例子,那将非常有用.谢谢

If someone could you give me an example it'll be very useful. Thanks

推荐答案

我认为这样的事情应该可行:

I think something like this should work:

@Configuration
public class YourConfiguration {

  @Bean(name = "org.dozer.Mapper")
  public DozerBeanMapper dozerBean() {
    List<String> mappingFiles = Arrays.asList(
      "dozer-global-configuration.xml", 
      "dozer-bean-mappings.xml",
      "more-dozer-bean-mappings.xml"
    );

    DozerBeanMapper dozerBean = new DozerBeanMapper();
    dozerBean.setMappingFiles(mappingFiles);
    return dozerBean;
  }

  ...
}

这篇关于如何在 Spring Boot 中使用推土机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆