angular js从http get响应中获取错误数组

xj3cbfub  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(192)

我正在用angularjs和java开发一个web应用程序,但是我在http get请求的响应数组方面遇到了问题。我有一个带有两个构造函数的类项:

public Item(int IdUnit, int ProductCode, String Brand, int AvailableItems, int RequiredItems, int OrderedItems,String Note, String Option)
public Item(int chassis, int engine, int body, int equipment, int tyres_brakes)

这是我获取请求的java方法:

@GET
@Path("items/{unit}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
public Response getAllItems(@PathParam("unit") String name) {
    List<Item> items = new ArrayList<>();
    try {
        Connection con = Condb.initializeDatabase();
        Statement statement = con.createStatement();
        ResultSet rs = statement.executeQuery("SELECT * FROM " + name);
        Item item;
        while (rs.next()) {             
            item = new Item(rs.getInt("idUnit"), rs.getInt("productCode"), rs.getString("brand"),
                    rs.getInt("availableItems"), rs.getInt("requiredItems"), rs.getInt("orderedItems"),
                    rs.getString("note"), filterOperation.checkOptional(name, rs));
            items.add(item);
        }
        con.close();
        return Response.ok(items).build();
    } catch (Exception exception) {
        exception.printStackTrace();
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}

这是我在java调试器中列出的“项”:

但在浏览器控制台中,我得到了以下日志:

数组长度正确,但内容不正确。我如何解决这个问题?
编辑:这是项目类
@xmlrootelement(name=“item”)公共类项{

public Item() {}

public Item(int IdUnit, int ProductCode, String Brand, int AvailableItems, int RequiredItems, int OrderedItems,String Note, String Option) {
    this.idUnit = IdUnit;
    this.productCode = ProductCode;
    this.brand = Brand;
    this.availableItems = AvailableItems;
    this.requiredItems = RequiredItems;
    this.orderedItems = OrderedItems;
    this.note = Note;
    this.option = Option;
}

public Item(int chassis, int engine, int body, int equipment, int tyres_brakes) {
    this.chassis = chassis;
    this.engine = engine;
    this.body = body;
    this.equipment = equipment;
    this.tyres_brakes = tyres_brakes;
}

private int chassis;
private int engine;
private int body;
private int equipment;
private int tyres_brakes;
final private String[] units = { "chassis", "engine", "body", "equipment", "tyres_brakes" };

@XmlElement(name = "idUnit")
private int idUnit;

@XmlElement(name = "productCode")
private int productCode;

@XmlElement(name = "brand")
private String brand;

@XmlElement(name = "availableItems")
private int availableItems;

@XmlElement(name = "requiredItems")
private int requiredItems;

@XmlElement(name = "orderedItems")
private int orderedItems;

@XmlElement(name = "note")
private String note;

@XmlElement(name = "option")
private String option;

public int getChassis() {
    return chassis;
}

public int getEngine() {
    return engine;
}

public int getBody() {
    return body;
}

public int getEquipment() {
    return equipment;
}

public int getTyres_brakes() {
    return tyres_brakes;
}

public String getUnits(int index) {
    return units[index];
}

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题