Converting Dto and Entity

本文介绍了如何在SpringBoot应用中集成并使用ModelMapper库。首先,需要添加ModelMapper的依赖到项目中。接着,在Spring配置中定义ModelMapper的bean。最后,展示了如何注入并使用ModelMapper来将对象映射为DTO。
摘要由CSDN通过智能技术生成

Using ModelMapper Library in Spring Boot App

Step 1: Add ModelMapper Library Dependency

<dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>3.1.1</version>
</dependency>

Step 2: Define the ModelMapper bean in our Spring configuration

@SpringBootApplication
public class BlogApplication {
    @Bean
    public ModelMapper modelMapper() {
        return new ModelMapper();
    }

    public static void main(String[] args) {
        SpringApplication.run(BlogApplication .class, args);
    }

}

Step 3: Inject and use ModelMapper

private  ObjectDto mapToDto(Object object ) {
        ObjectDto objectDto = modelMapper.map(object ,ObjectDto.class);
        return objectDto ;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值