如何解决试图将数据从 servlet 发送到 java,但有映射错误
我正在使用 servlet,并尝试将数据从 html 发送到 Java 应用程序。然后返回数据。 我遇到了一个错误。
Cannot deserialize value of type `int` from Object value (token `JsonToken.START_OBJECT`)
at [Source: (String)"{"reimb_type_id":{},"reimb_amount":{},"reimb_description":null}"; line: 1,column: 18] (through reference chain: com.revature.models.ReimbursementsDTO["reimb_type_id"])
它所说的代码,它来自:
public int reim_id;
public int reimb_type_id;
public int reimb_status_id;
public int reimb_amount;
public String reimb_description;
public ReimbursementsDTO(int reimb_status_id) {
super();
this.reimb_status_id = reimb_status_id;
}
public ReimbursementsDTO(int reim_id,int reimb_status_id) {
super();
this.reim_id = reim_id;
this.reimb_status_id = reimb_status_id;
}
public ReimbursementsDTO() {
super();
}
public ReimbursementsDTO(int reimb_type_id,int reimb_amount,String reimb_description) {
super();
this.reimb_type_id = reimb_type_id;
this.reimb_amount = reimb_amount;
this.reimb_description = reimb_description;
}
```
I tried to pass in values into a method but encountered this problem every single time.
public void submitReimbursements(int reimb_type_id,String reimb_description) {
try(Connection connection = ConnectionUtil.getConnection()) {
ResultSet resultSet = null; // intialize an empty resultset that will store the results of our query.
//sql statement to get all of the info from reimbursement
String sql = "INSERT into \"P1\".reimbursements"
+ "(reimb_amount,reimb_submitted,reimb_resolved,reimb_description,"
+ "reimb_author,reimb_resolver,reimb_status_id,reimb_type_id)"
+ "values (?,?,null,1,2,?);";
java.sql.Statement statement = connection.createStatement();
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1,reimb_type_id);
preparedStatement.setInt(2,reimb_amount );
preparedStatement.setString(3,reimb_description );
//preparedStatement.setInt(4,0);
statement.executeQuery(sql);
}catch (Exception e) {
// TODO: handle exception
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。