如何在Spring Boot中使用Dozer? [英] How to use Dozer with Spring Boot?
问题描述
我正在开发一个Spring Boot项目。我只有注释配置。我想包括推土机将实体转换为DTO,将DTO转换为实体。我在dozer网站上看到,他们解释说我必须在spring xml配置文件中添加以下配置。由于我没有xml文件而是注释配置Java类,我不知道如何将其转换为Java Configuration类。
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中使用Dozer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!