2016-06-10 167 views
1

目前我的系统有一个基本接口,其中包含4个映射器方法。Selma映射器泛型转换BaseMapper <T扩展BaseDomain,D扩展BaseDTO>

构建出错信息出现后,有人让我知道它是什么?我已经尝试了很多方法,必须将这四种通用方法转换为crudservice的某些点。

Error:java: Failed to generate mapping method for type br.com.cron.pdv.domain.Imposto to br.com.cron.pdv.service.service.ImpostoService not supported on br.com.cron.pdv.service.mapper.BaseServiceMapper.asDTO(T) ! --> Add a custom mapper or 'withIgnoreFields' on @Mapper or @Maps to fix this ! If you think this a Bug in Selma please report issue here [ https://github.com/xebia-france/selma/issues] .

下面的BaseMapper:

public interface BaseServiceMapper<T extends BaseDomain, D extends BaseDTO> { 

    //Server X Domain 
    T asDomain(D source); 

    List<T> asDomains(List<D> source); 

    D asDTO(T source); 

    List<D> asDTOs(List<T> source); 

} 

接口扩展:

@Mapper(withIgnoreMissing = IgnoreMissing.ALL, withIoC = IoC.SPRING) 
public interface ImpostoMapper extends BaseServiceMapper<Imposto, ImpostoDTO> { 

} 

我的服务:

public interface ImpostoService extends BaseService<Imposto, Long> { 
} 

我的服务:

public interface BaseService<T, ID extends Serializable> { 

    public T salvar(T t); 

    public List<T> salvar(List<T> t); 

    public List<T> listarTodos(); 

    public T buscarPor(ID id); 

    List<T> buscarPorDataAtualizacao(LocalDateTime dataInicial, LocalDateTime dataFinal); 

    public List<T> listarAtivos(); 

    public void remover(ID id); 

    public void remover(T t); 

    public void remover(Iterable<T> iterable); 

    public void desativar(T t); 

    public void ativar(T t); 
} 

我CrudBaseService:

public abstract class CrudController<T extends BaseDomain, D extends BaseDTO, ID extends Serializable> { 


     protected BaseResponse response; 
     private BaseService<T, ID> service; 
     private BaseServiceMapper<T, D> mapper; 


     public CrudController(BaseService<T, ID> service, BaseServiceMapper<T, D> mapper) { 
      this.service = service; 
      this.mapper = mapper; 
     } 

     public abstract ResponseEntity<List<T>> listarTodos(); 

     public abstract ResponseEntity<List<T>> listarAtivos(); 

     public abstract ResponseEntity<T> buscar(@PathVariable(ID) Long id); 

     public abstract ResponseEntity<Void> cadastrar(@ModelAttribute T t, UriComponentsBuilder uriComponentsBuilder); 

     public abstract ResponseEntity<T> atualizar(@PathVariable(ID) Long id, @ModelAttribute T t); 

     public abstract RedirectView remover(@PathVariable(ID) Long id); 

     @RequestMapping(value = REQUEST_MAPPING_INTEGRACAO_DATA, method = RequestMethod.GET) 
     public ResponseEntity<BaseResponse> buscarPorDataAtualizacao(@RequestParam(name = DATA_INICIAL, required = false) String dataInicial, 
                    @RequestParam(name = DATA_FINAL, required = false) String dataFinal) { 

      response = new BaseResponse(); 

      if (isNullOrEmpty(dataInicial) || isNullOrEmpty(dataFinal)) { 
       response.adicionarErro("Existe data(s) vazia(s) ou no formato incorreto"); 
       return createResponse(response); 
      } 

      LocalDateTime dtInicial; 
      LocalDateTime dtFinal; 

      try { 
       dtInicial = parseLocaleDateTimeWithoutHour(dataInicial); 
       dtFinal = parseLocaleDateTimeWithoutHour(dataFinal); 
      } catch (Exception ex) { 
       response.adicionarErro(ex.getMessage()); 
       return createResponse(response); 
      } 

      List<T> result = service.buscarPorDataAtualizacao(dtInicial, dtFinal); 

      List<D> resultDTO = null;//mapper.asDTOs(result); 
      response.setResult(resultDTO); 

      if (resultDTO.isEmpty()) { 
       return createResponse(response, HttpStatus.NOT_FOUND); 
      } 

      return createResponse(response); 
     } 

     ResponseEntity<BaseResponse> createResponse(BaseResponse result) { 
      return new ResponseEntity<>(result, result.getSucesso() ? HttpStatus.OK : HttpStatus.BAD_REQUEST); 
     } 

     ResponseEntity<BaseResponse> createResponse(BaseResponse result, HttpStatus status) { 
      return new ResponseEntity<>(result, status); 
     } 
    } 

我的控制器休息:

@RestController 
@RequestMapping(ImpostoController.REQUEST_MAPPING_IMPOSTO) 
public class ImpostoController extends CrudController<Imposto, ImpostoDTO, Long> { 

      public static final String REQUEST_MAPPING_IMPOSTO = "imposto"; 

      private ImpostoService impostoService; 
      private ImpostoMapper mapper; 

      @Autowired 
      public ImpostoController(ImpostoService service, ImpostoMapper mapper) { 
       super(service, mapper); 
       this.impostoService = service; 
       this.mapper = mapper; 
      } 

      @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) 
      public ResponseEntity<List<Imposto>> listarTodos() { 
       List<Imposto> impostoList = impostoService.listarTodos(); 
       if (impostoList.isEmpty()) { 
        return new ResponseEntity<>(HttpStatus.NO_CONTENT); 
       } 
       return new ResponseEntity<>(impostoList, HttpStatus.OK); 
      } 

      @Override 
      @RequestMapping(value = REQUEST_MAPPING_ATIVOS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) 
      public ResponseEntity<List<Imposto>> listarAtivos() { 
       List<Imposto> impostoList = impostoService.listarAtivos(); 
       if (impostoList.isEmpty()) { 
        return new ResponseEntity<>(HttpStatus.NO_CONTENT); 
       } 
       return new ResponseEntity<>(impostoList, HttpStatus.OK); 
      } 

      @Override 
      @RequestMapping(value = REQUEST_MAPPING_ID, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) 
      public ResponseEntity<Imposto> buscar(@PathVariable(ID) Long id) { 
       Imposto imposto = impostoService.buscarPor(id); 
       if (imposto == null) { 
        return new ResponseEntity<>(HttpStatus.NOT_FOUND); 
       } 
       return new ResponseEntity<>(imposto, HttpStatus.OK); 
      } 

      @Override 
      @RequestMapping(value = REQUEST_MAPPING_CADASTRAR, method = RequestMethod.POST) 
      public ResponseEntity<Void> cadastrar(@RequestBody Imposto imposto, UriComponentsBuilder uriComponentsBuilder) { 
       impostoService.salvar(imposto); 
       HttpHeaders httpHeaders = new HttpHeaders(); 
       httpHeaders.setLocation(uriComponentsBuilder.path(REQUEST_MAPPING_ID).buildAndExpand(imposto.getId()).toUri()); 
       return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); 
      } 

      @Override 
      @RequestMapping(value = REQUEST_MAPPING_ATUALIZAR, method = RequestMethod.PUT) 
      public ResponseEntity<Imposto> atualizar(@PathVariable(ID) Long id, @Validated @RequestBody Imposto imposto) { 
       Imposto impostoEmBanco = impostoService.buscarPor(id); 

       if (impostoEmBanco == null) { 
        return new ResponseEntity<>(HttpStatus.NOT_FOUND); 
       } 

       if (imposto.isSituacao()) impostoEmBanco.ativar(); 
       else impostoEmBanco.desativar(); 

       try { 
        impostoService.salvar(impostoEmBanco); 
       } catch (Exception e) { 
        return new ResponseEntity<>(HttpStatus.EXPECTATION_FAILED); 
       } 
       return new ResponseEntity<>(impostoEmBanco, HttpStatus.OK); 
      } 

      @Override 
      @RequestMapping(value = REQUEST_MAPPING_REMOVER, method = RequestMethod.DELETE) 
      public RedirectView remover(@PathVariable(ID) Long id) { 
       Imposto imposto = impostoService.buscarPor(id); 
       impostoService.remover(imposto); 
       return new RedirectView(REQUEST_MAPPING_IMPOSTO); 
      } 

     } 

回答

0

我刚看到你的问题。 Selma版本0.15应该可以解决这个问题。现在,从BaseServiceMapper的方法从ImpostoMapper透视图中读取。