- package com.lezu.springboot.common.dto;
-
- import lombok.AllArgsConstructor;
- import lombok.Builder;
- import lombok.Data;
- import lombok.NoArgsConstructor;
- import lombok.experimental.Accessors;
-
- import java.math.BigDecimal;
-
- @Data
- @AllArgsConstructor
- @NoArgsConstructor
- @Builder
- @Accessors(chain = true)
- public class UserDto {
- private String name;
- private Integer qty;
- private BigDecimal money;
-
- }
-
-
-
- package com.lezu.springboot.test.lian;
-
- import com.lezu.springboot.common.dto.UserDto;
-
- import java.math.BigDecimal;
-
- public class Test1 {
- public static void main(String[] args) {
- //使用@Accessors(chain = true)
- UserDto userDto1 = new UserDto().setMoney(new BigDecimal("11")).setName("张三").setQty(11);
- System.out.println(userDto1);
- //UserDto(name=张三, qty=11, money=11)
-
-
-
- //使用@Builder
- UserDto userDto2 = UserDto.builder().money(new BigDecimal("11")).name("李四").qty(11).build();
- System.out.println(userDto2);
- //UserDto(name=李四, qty=11, money=11)
-
- }
- }
-
@Accessors
@Builder