Skip to content

ckpoint/EntityMapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Entity-Mapper

EntityMapper is an intelligent object mapping library that automatically maps objects to Entity class.

EntityMapper depends on [Project Lombok, JODA TIME]

※EntityMaper does not need a setter and getter

Installation

1. MAVEN

 <dependency>
   <groupId>com.github.ckpoint</groupId>
   <artifactId>entity-mapper</artifactId>
   <version>0.0.1</version>
 </dependency>

2. GRADLE

  compile group: 'com.github.ckpoint', name: 'entity-mapper', version: '0.0.1'

Table of Contents

Create Entity

A. extends MapEntity

- MapEntity only has automatic mapping function.

@Entity
@Getter
public class Account extends MapEntity {
    private String name;
    private String email;
    private Long age;
    private Gender gender;

}

B. extends MapBaseEntity

- MapBaseEntity has automatic mapping function and Long type id field.

@Entity
@Getter
public class Account extends MapBaseEntity{
    private String name;
    private String email;
    private Long age;
    private Gender gender;

}

C. extends MapAuditEntity

- MapAuditEntity has automatic mapping function and id, createdAt, updatedAt fields.

@Entity
@Getter
public class Account extends MapAuditEntity{
    private String name;
    private String email;
    private Long age;
    private Gender gender;

}

Update Entity

  • The class inheriting EntityMapper has a function called updateFromObj
  • EntityMaper does not need a setter method.

for exmaple

    public void updateEntityTest() {
        AccountModel hsimModel = new AccountModel();
        hsimModel.setAge(25L);
        hsimModel.setEmail("hsim@daou.co.kr");
        hsimModel.setGender("MAN");
        hsimModel.setName("hsim");

        Account hsim = new Account();
        hsim.updateFromObj(hsimModel);
    }

Handling Field Method

  • If you want to exclude certain fields or setter functions from automatic mapping, You just need to put the @IgnoreUpdateFromObj annotation.

for exmaple

@Entity
@Getter
public class Account extends MapAuditModel {
    private String name;
    private String email;

    @IgnoreUpdateFromObj
    private Long age;

    private Gender gender;

    @IgnoreUpdateFromObj
    public void setAge(Long age) {
        this.age = age;
    }
}

About

Entity fields auto mapper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages