mapstruct / mapstruct.org

Web site of the MapStruct project
63 stars 40 forks source link

defaultValue is not work. how to fix it ; #125

Closed hushunjian closed 2 years ago

hushunjian commented 3 years ago
@Mapping(target = "id", source = "id", defaultValue = "")
Tree toTree(String id, String name, String parentId, String parentFullName, String parentFullId, Integer orderNum, String path, Integer level);

@Override

public Tree toTree(String id, String name, String parentId, String parentFullName, String parentFullId, Integer orderNum, String path, Integer level) {

    if ( id == null && name == null && parentId == null && parentFullName == null && parentFullId == null && orderNum == null && path == null && level == null ) {

        return null;
    }

    Tree tree = new Tree();

    if ( id != null ) {

        if ( id != null ) {

            tree.setId( id );
        }

        else {

            tree.setId( "" );
        }
    }

    if ( name != null ) {

        tree.setName( name );
    }

    if ( parentId != null ) {

        tree.setParentId( parentId );
    }

    if ( parentFullName != null ) {

        tree.setParentFullName( parentFullName );
    }

    if ( parentFullId != null ) {

        tree.setParentFullId( parentFullId );
    }

    if ( orderNum != null ) {

        tree.setOrderNum( orderNum );
    }

    if ( path != null ) {

        tree.setPath( path );
    }

    if ( level != null ) {

        tree.setLevel( level );
    }

    return tree;
}
hushunjian commented 3 years ago

defaultValue is not working

filiphr commented 2 years ago

Please use StackOverflow or GitHub Discussions for asking questions