public enum NullValuePropertyMappingStrategy {
/**
* If a source bean property equals {@code null} the target bean property will be set explicitly to {@code null}.
*/
SET_TO_NULL,
/**
* If a source bean property equals {@code null} the target bean property will be set to its default value.
*
* This means:
*
*
For {@code List} MapStruct generates an {@code ArrayList}
*
For {@code Map} a {@code HashMap}
*
For arrays an empty array
*
For {@code String} {@code ""}
*
for primitive / boxed types a representation of {@code 0} or {@code false}
*
For all other objects an new instance is created, requiring an empty constructor.
*
*
* Make sure that a {@link Mapping#defaultValue()} is defined if no empty constructor is available on
* the default value.
*/
SET_TO_DEFAULT,
/**
* If a source bean property equals {@code null} the target bean property will be ignored and retain its
* existing value.
*/
IGNORE;
}
指定不映射某些值
@Data
@AllArgsConstructor
public class Source {
private Integer id;
private String name;
}
@Data
@AllArgsConstructor
public class Target {
private Integer id;
private String name;
}
@Mapper
public interface Converter {
Converter INSTANCE = Mappers.getMapper(Converter.class);
// name 值不做映射
@Mapping(source = "name", target = "name", ignore = true)
Target fromSource(Source source);
@InheritInverseConfiguration
Source toSource(Target target);
}
通过 @Mapping#ignore=true 来指定不需要做映射的值
@Data
@AllArgsConstructor
public class Source {
private Integer id;
private List itemList;
}
@Data
@AllArgsConstructor
public class SourceItem {
private String identifier;
}
@Data
@AllArgsConstructor
public class Target {
private Integer id;
private List itemList;
}
@Data
@AllArgsConstructor
public class TargetItem {
private String identifier;
}
@Mapper
public interface SourceItemConverter {
SourceItemConverter INSTANCE = Mappers.getMapper(SourceItemConverter.class);
TargetItem fromSourceItem(SourceItem sourceItem);
SourceItem toSourceItem(TargetItem targetItem);
}
@Mapper
public interface SourceConverter {
SourceConverter INSTANCE = Mappers.getMapper(SourceConverter.class);
Target fromSource(Source source);
Source toSource(Target target);
}
public class Test {
public static void main(String[] args) {
testFromSource();
testToSource();
}
private static void testFromSource(){
Target target = SourceConverter.INSTANCE.fromSource(new Source(1, Arrays.asList(new SourceItem("111"), new SourceItem("112"))));
System.out.println(target);
}
private static void testToSource(){
Source source = SourceConverter.INSTANCE.toSource(new Target(2, Arrays.asList(new TargetItem("222"), new TargetItem("223"))));
System.out.println(source);
}
}
各写各的映射器,应用的时候是需要调用最外层的映射器即可。
更新目标类而不是新建目标类
@Data
@AllArgsConstructor
public class Source {
private Integer id;
private String name;
}
@Data
@AllArgsConstructor
public class Target {
private Integer id;
private String name;
}
@Mapper
public interface Converter {
Converter INSTANCE = Mappers.getMapper(Converter.class);
/**
* id 不做更新,其他 source 的属性更新到 target
* @param source
* @param target
*/
@Mapping(target = "id", ignore = true)
void fromSource(Source source, @MappingTarget Target target);
}
public class Test {
public static void main(String[] args) {
testFromSource();
}
private static void testFromSource(){
Source source = new Source(1, "sourceName");
Target target = new Target(2, "targetName");
Converter.INSTANCE.fromSource(source, target);
System.out.println(target);
}
}
只需要在调用该对象合适(比如下列的setStyles)的方法后让该方法返回该对象(通过this 因为一旦一个函数称为一个对象方法的话那么在这个方法内部this(结合下面的setStyles)指向这个对象)
function create(type){
var element=document.createElement(type);
//this=element;
JAX-WS
SOAP Version 1.2 Part 0: Primer (Second Edition)
SOAP Version 1.2 Part 1: Messaging Framework (Second Edition)
SOAP Version 1.2 Part 2: Adjuncts (Second Edition)
Which style of WSDL
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml