![](/img/trans.png)
[英]Spring Boot exception "java.lang.IllegalArgumentException: Not a managed type:"
[英]Spring Boot: Type cannot be null; nested exception is java.lang.IllegalArgumentException: Type cannot be null when running Stored Procedue
早上好,我是Spring Boot的新手,我正在執行一個休息服務,必須調用存儲在數據庫中的一個過程,問題是你收到手機並且必須返回一個代碼和結果,如下所示:
這是我的代碼:
主類
package com.app.validacion;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
控制器
package com.app.validacion.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.app.validacion.dao.DriverBonificadosRepository;
import com.app.validacion.entity.RespuestaVo;
@RestController
public class DriverBonificadosController {
@Autowired
private DriverBonificadosRepository dao;
@GetMapping("/service/{movil}")
public RespuestaVo ConsultarMovil(@PathVariable String movil) {
return dao.validarClienteBonifiado(movil);
}
}
存儲庫
package com.app.validacion.dao;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.CrudRepository;
import com.app.validacion.entity.DriverBonificados;
import com.app.validacion.entity.RespuestaVo;
public interface DriverBonificadosRepository extends CrudRepository<DriverBonificados, Integer> {
@Procedure(procedureName="ValidacionClienteBonificado")
RespuestaVo validarClienteBonifiado(String pMovil);
}
我的實體
import javax.persistence.NamedStoredProcedureQueries;
import javax.persistence.NamedStoredProcedureQuery;
import javax.persistence.ParameterMode;
import javax.persistence.StoredProcedureParameter;
import javax.persistence.Table;
@NamedStoredProcedureQueries({
@NamedStoredProcedureQuery(
name="SPValidationClienteBonus4G",
procedureName="ValidacionClienteBonificado",
parameters = {
@StoredProcedureParameter(mode=ParameterMode.IN, name="p_movil",type=String.class),
@StoredProcedureParameter(mode=ParameterMode.OUT, name="code",type=String.class),
@StoredProcedureParameter(mode=ParameterMode.OUT, name="result",type=String.class),
})
})
@Entity
@Table
public class DriverBonificados {
@Id
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getMovil() {
return movil;
}
public void setMovil(String movil) {
this.movil = movil;
}
public String getContador() {
return contador;
}
public void setContador(String contador) {
this.contador = contador;
}
public Date getFecha_driver() {
return fecha_driver;
}
public void setFecha_driver(Date fecha_driver) {
this.fecha_driver = fecha_driver;
}
public Date getFecha_alta() {
return fecha_alta;
}
public void setFecha_alta(Date fecha_alta) {
this.fecha_alta = fecha_alta;
}
public Date getFecha_fin() {
return fecha_fin;
}
public void setFecha_fin(Date fecha_fin) {
this.fecha_fin = fecha_fin;
}
public Date getCodigo_transaccion() {
return codigo_transaccion;
}
public void setCodigo_transaccion(Date codigo_transaccion) {
this.codigo_transaccion = codigo_transaccion;
}
private String movil;
private String contador;
private Date fecha_driver;
private Date fecha_alta;
private Date fecha_fin;
private Date codigo_transaccion;
我的課堂 RespuestaVo
package com.app.validacion.entity;
public class RespuestaVo {
private String code;
private String result;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}
我收到以下錯誤(移動參數必須作為字符串接收,因為在數據庫中它被發現為 Varchar):
任何人都知道如何解決這個問題? 如果或如果我需要通過存儲過程進行咨詢
更新
使用@Query,修改代碼如下:
package com.app.validacion.dao;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import com.app.validacion.entity.DriverBonificados;
import com.app.validacion.entity.RespuestaVo;
public interface DriverBonificadosRepository extends CrudRepository<DriverBonificados, Integer> {
@Query(nativeQuery = true,value = "call ValidacionClienteBonificado(:movil)")
RespuestaVo validarClienteBonifiado(@Param("movil") String pMovil);
}
我收到以下錯誤:
org.springframework.core.convert.ConverterNotFoundException:找不到能夠從類型 [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] 轉換為類型 [com.app.validacion.entity.RespuestaVo] 的轉換器在 org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE] 在 org.springframework.core.convert。 support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE] 在 org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java :174) ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE] 在 org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.convert(ResultProcessor.java:297) ~[spring- data-commons-2.2.1.RELEASE.jar:2.2.1.RELEASE] 在 org.springframework.data.repository.query.ResultProcessor$ChainingConverter.lam bda$and$0(ResultProcessor.java:217) ~[spring-data-commons-2.2.1.RELEASE.jar:2.2.1.RELEASE] 在 org.springframework.data.repository.query.ResultProcessor$ChainingConverter.convert( ResultProcessor.java:228) ~[spring-data-commons-2.2.1.RELEASE.jar:2.2.1.RELEASE] 在 org.springframework.data.repository.query.ResultProcessor.processResult(ResultProcessor.java:170) ~ [spring-data-commons-2.2.1.RELEASE.jar:2.2.1.RELEASE] 在 org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:157) ~[spring-data- jpa-2.2.1.RELEASE.jar:2.2.1.RELEASE]
解決了
我設法解決了我的問題,使用 @Query 注釋,並為我將要接收的響應構建了一個接口,在這些情況下有 2 種方法(根據我將接收的參數數量),有了這個,我得到了我在 Json 中的回答,我將界面代碼保留在下面:
public interface RespuestaVo {
String getCode();
String getResult();
}
我建議使用 @Query 來運行帶有 Spring Boot 的存儲過程
嘗試這個 -
@GetMapping("/service/{movil}")
public RespuestaVo ConsultarMovil(@PathVariable("movil") String movil) {
return dao.validarClienteBonifiado(movil);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.