这是我的 API 的响应:
"The number of parameters to execute should be consistent with the expected number of parameters = [2] but the actual number is [0]."
我使用 pgClient、Vert.x 3.9.3 并毫无问题地使用各种 REST API,但是....在这个查询中(可能是错误的)
private static final String SELECT_CBA = "select art.leyenda, $1::numeric(10,3) as cantidad, uni.abreviatura, \r"
+ "round(((art.precio_costo * (art.utilidad_fraccionado/100)) + art.precio_costo) * $2::numeric(10,3),2) as totpagar \r"
+ "FROM public.articulos art join public.unidades uni on uni.idunidad = art.idunidad \r"
+ "WHERE (substring(art.codigobarra,1,2) = \'$3\' and substring(art.codigobarra,3,6) = \'$4\')";
一些解释
$1 和 $2 是相同的参数;$2 和 $3 必须是带引号的参数。这是我的休息垂直:
poolClient = PgPool.pool(vertx, options, poolOptions);
bizArticulo = new BizArticulo(poolClient);
Router router = Router.router(vertx);
router.route("/api/articulos*").handler(BodyHandler.create());
router.get("/api/articulos").handler(bizArticulo::getAll);
router.get("/api/articulos/:cantcomp1/:cantcomp2/:tipoprod/:prodpadre").handler(bizArticulo::getOneReadingBarcode);
其中 :cantcomp1 -> $1, :cantcomp2 -> $2, :tipoprod -> $3 和 $4 -> :prodpadre
最后,这是我的“生意”
public void getOneReadingBarcode(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
pgClient
.preparedQuery(SELECT_CBA)
.execute(ar -> {
if (ar.succeeded()) {
RowSet<Row> rows = ar.result();
List<Articulo> articulos = new ArrayList<>();
rows.forEach(row -> {
articulos.add(fromBarCode(row));
});
response.putHeader("content-type", "application/json; charset=utf-8")
.setStatusCode(200)
.end(Json.encodePrettily(articulos));
} else {
System.out.println("Failure: " + ar.cause().getMessage());
response.putHeader("content-type", "application/json; charset=utf-8")
.end(Json.encodePrettily(ar.cause().getMessage()));
}
});
}
在邮递员中,我写道:
192.168.0.15:8092/api/articulos/0.750/0.750/20/021162 ;_ _ _ _ _ _ _ 我假设参数匹配,但它返回上面提到的错误。怎么了?任何帮助将不胜感激埃内斯托