Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Boot:类型不能为空;嵌套异常为java.lang.IllegalArgumentException:运行存储过程时,类型不能为null_Java_Spring Boot - Fatal编程技术网

Spring Boot:类型不能为空;嵌套异常为java.lang.IllegalArgumentException:运行存储过程时,类型不能为null

Spring Boot:类型不能为空;嵌套异常为java.lang.IllegalArgumentException:运行存储过程时,类型不能为null,java,spring-boot,Java,Spring Boot,早上好,我是Spring Boot新手,我正在执行一个rest服务,该服务必须调用存储在数据库中的过程,问题是您收到手机并且必须返回代码和结果,如下所示: 这是我的代码: 主类 package com.app.validacion; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBoot

早上好,我是Spring Boot新手,我正在执行一个rest服务,该服务必须调用存储在数据库中的过程,问题是您收到手机并且必须返回代码和结果,如下所示:

这是我的代码:

主类

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);
}
我的班级

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;
    }

}
我得到了以下错误,mobile参数必须作为字符串接收,因为在数据库中它被发现为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.handleConverterNotFoundGenericConversionService.java:321 ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]位于 org.springframework.core.convert.support.GenericConversionService.convertGenericConversionService.java:194 ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]位于 org.springframework.core.convert.support.GenericConversionService.convertGenericConversionService.java:174 ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]位于 org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.convertResultProcessor.java:297 ~[spring-data-commons-2.2.1.RELEASE.jar:2.2.1.RELEASE]位于 org.springframework.data.repository.query.ResultProcessor$ChainingConverter.lambda$和$0ResultProcessor.java:217 ~[spring-data-commons-2.2.1.RELEASE.jar:2.2.1.RELEASE]位于 org.springframework.data.repository.query.ResultProcessor$ChainingConverter.convertResultProcessor.java:228 ~[spring-data-commons-2.2.1.RELEASE.jar:2.2.1.RELEASE]位于 org.springframework.data.repository.query.ResultProcessor.processResultResultProcessor.java:170 ~[spring-data-commons-2.2.1.RELEASE.jar:2.2.1.RELEASE]位于 org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecuteAbstractJpaQuery.java:157 ~[spring-data-jpa-2.2.1.RELEASE.jar:2.2.1.RELEASE]

试试这个-

@GetMapping("/service/{movil}")
public RespuestaVo  ConsultarMovil(@PathVariable("movil") String movil) {
    return dao.validarClienteBonifiado(movil);

}
解决

我设法解决了我的问题,使用@Query注释,并为我将要接收的响应构建了一个接口,在这些情况下,根据我将接收的参数数量,使用2个方法,通过这个方法,我得到了Json中的答案,我将接口代码保留在下面:

public interface RespuestaVo {

    String getCode();
    String getResult();

}
我建议使用@Query在Spring引导下运行存储过程

public interface RespuestaVo {

    String getCode();
    String getResult();

}