目前我的系统有一个基本界面,其中包含4个映射器方法。
出现构建错误消息后,有人让我知道它是什么?我已经尝试了很多方法,必须将这四种通用方法转换为crudservice的某些点。
错误:java:无法为类型生成映射方法 br.com.cron.pdv.domain.Imposto to 不支持br.com.cron.pdv.service.service.ImpostoService br.com.cron.pdv.service.mapper.BaseServiceMapper.asDTO(T)! - >加 @Mapper或@Maps上的自定义映射器或'withIgnoreFields'来解决此问题 !如果您认为这是Selma中的Bug,请在此处报告问题 [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 :(得分:0)
我刚看到你的问题。 Selma发布0.15应该可以解决这个问题。现在,从ImpostoMapper透视图中读取BaseServiceMapper中的方法。