我想将数据库表的数据获取到客户端。我通过 JSON 发送数据。当我在客户端打印输出结果时,它会给出以下结果。
{"pricing":null}
当我在服务器端打印返回语句时,它输出以下内容
[Connection.Pricing@3d5bae2]
没有错误。我做错了什么?
这是我的客户端代码
public String loadTable(String tablename) throws ClientProtocolException, IOException {
pathParams.add("tablename", tablename);
ClientResponse response = service.path("access").path("loadtable").queryParams(pathParams).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
String responseString = response.getEntity(String.class);
return responseString;
这是我的服务器端
@Path("/loadtable")
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Pricing> loadTable(@QueryParam("tablename") String tablename) throws Exception {
List<Pricing> pricing = new ArrayList<Pricing>();
try {
query = c.prepareStatement("select * from " + tablename);
ResultSet ets_rs = query.executeQuery();
while (ets_rs.next()) {
pricing.add(new Pricing(ets_rs.getString(1), ets_rs.getString(2), ets_rs.getString(3), ets_rs.getString(4), ets_rs.getString(5), ets_rs.getString(6)));
}
query.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (c != null) {
c.close();
}
}
return pricing;
这是我在服务器端的 POJO 类
@XmlRootElement
class Pricing {
String category;
String lower_limit;
String class_no;
String value;
String employee;
String upper_limit;
public Pricing() {
}
Pricing(String a, String b, String c, String d, String e, String f) {
category = a;
lower_limit = b;
upper_limit = c;
class_no = d;
value = e;
employee = f;
}
//getters
}