Java MyBatis无法在查询上设置参数

Java MyBatis无法在查询上设置参数,java,spring,mybatis,Java,Spring,Mybatis,Mybatis抛出一个错误,表示设置参数有问题。有什么不对劲吗?我测试了SQL查询,结果很好。我用的是带弹簧的渐变 查询数据库时出错。 原因:org.postgresql.util.PSQLException:错误:语法错误位于或接近 客户职位:245 该错误可能存在于services/CustomerService.java最佳猜测中 错误可能涉及services.CustomerService.findbypersonalcode和country-Inline 设置参数时出错 代码: 控制器

Mybatis抛出一个错误,表示设置参数有问题。有什么不对劲吗?我测试了SQL查询,结果很好。我用的是带弹簧的渐变

查询数据库时出错。 原因:org.postgresql.util.PSQLException:错误:语法错误位于或接近 客户职位:245 该错误可能存在于services/CustomerService.java最佳猜测中 错误可能涉及services.CustomerService.findbypersonalcode和country-Inline 设置参数时出错

代码:

控制器

@RestController
@RequestMapping(value = "/v1/customers", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class CustomerController {

   private CustomerService customerService;

    public CustomerController(@Autowired CustomerService customerService) {
        this.customerService = customerService;
    }

    @GetMapping("/{personalCode}")
    public List<Customer> getCustomersByPersonalCode(@PathVariable String personalCode, @RequestHeader String country) {
        return customerService.findByPersonalCodeAndCountry(personalCode, country);
    }
}

您可以尝试下面的代码吗

Controller method :
     @GetMapping("/{personalCode}")
        public List<Customer> getCustomersByPersonalCode(@PathVariable String personalCode, @RequestHeader(value="country") String country) {
            return customerService.findByPersonalCodeAndCountry(personalCode, country);
        }

@Results(value = { @Result(column = "id", property = "id"), 
        @Result(column = "cust_personal_code", property = "personalCode"), 
        @Result(column = "cust_bank_country ", property = "country")
    )}
    @Select("Select * FROM customer WHERE cust_personal_code= #{personalCode} AND cust_bank_country = #{country}")
    List<Customer> findByPersonalCodeAndCountry(@Param("personalCode") String personalCode, @Param("country") String country);
其中id、个人代码、国家/地区:客户POJO中的变量 表->idInteger、客户个人代码字符串、客户银行国家字符串:表中的列


很抱歉,当我在hereDid中粘贴代码时,逗号只是输入错误。您尝试给出结果集和整个代码更改?@jodymilers您能提供表格详细信息吗?还要确保您正在导入包org.apache.ibatis.annotations.Paramadded imports和table@jodymilers表格详情?列的类型?我认为问题可能在于表中的不同数据类型和您的参数类型。如果查询语法不正确,通常会发生此错误,例如,选择*customer where。。。。可能是您的查询不正确,然后修复了它,但仍在运行旧代码?我建议在mybatis或postgres中启用查询日志记录,并检查在DB中真正发送和执行的查询
Controller method :
     @GetMapping("/{personalCode}")
        public List<Customer> getCustomersByPersonalCode(@PathVariable String personalCode, @RequestHeader(value="country") String country) {
            return customerService.findByPersonalCodeAndCountry(personalCode, country);
        }

@Results(value = { @Result(column = "id", property = "id"), 
        @Result(column = "cust_personal_code", property = "personalCode"), 
        @Result(column = "cust_bank_country ", property = "country")
    )}
    @Select("Select * FROM customer WHERE cust_personal_code= #{personalCode} AND cust_bank_country = #{country}")
    List<Customer> findByPersonalCodeAndCountry(@Param("personalCode") String personalCode, @Param("country") String country);