【java】mapstruct自定义类的转换示例

//通过createUserId获取到createUserName
@Mappings({
		@Mapping(target = "createUserName", expression = "java(com.test.NameConverter.getUserNameById(entity.getCreateUserId()))"),
	})
	StudentVO studentEntityTOVO(StudentEntity entity);
public class NameConverter {
	public static String getUserNameById(String id){
		//通过id获取用户姓名
		StudentEntity student = StudentCache.getStudent(id);
		if(student !=null){
			return student .getName();
		}
		return null;
	}
}

你可能感兴趣的:(java,java)