Mybatis抛出错误,表明设置参数存在问题。有什么事吗我测试了SQL查询,这很好。我正在使用Spring的Graddle。
查询数据库时出错。
原因:org.postgresql.util.PSQLException:错误:或附近的语法错误 “客户”位置:245
该错误可能存在于services / CustomerService.java中(最佳猜测)
该错误可能涉及services.CustomerService.findByPersonalCodeAndCountry-Inline
设置参数时发生错误
代码:
import com.luminor.dc.ccc.contracts.dao.Customer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface CustomerService {
@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);
}
控制器
@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);
}
}
表
答案 0 :(得分:-1)
您可以尝试以下代码吗?
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,personalCode,country:客户POJO中的变量 Table-> id(Integer),cust_personal_code(String),cust_bank_country(String):表中的列