在REST API中发布失败

问题描述 投票:0回答:1

这是我的人对象。

persons
+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| id          | int(11)     | NO   | PRI | NULL    | auto_increment |
| given_name  | varchar(30) | NO   |     | NULL    |                |
| family_name | varchar(30) | NO   |     | NULL    |                |
+-------------+-------------+------+-----+---------+----------------+

Here's the method that does the posting,




 public static void addPerson(Person person) {
            String givenName = person.getGivenName();
            String familyName = person.getFamilyName();

            String queryString = "INSERT INTO persons (given_name, family_name) VALUES (" + givenName + " , " + familyName +" );";
            Connector connector = null;
            try {
                connector = Connector.getInstance();
                connector.executeQuery(queryString);
            } catch (SQLException e1) {

                e1.printStackTrace();
            }

        }

这是使用JAX-RS进行POST的服务方法

@POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public void addPerson(Person person){

        TeacherService.addPerson(person);
    }

问题是该对象未发布,因为该行未保存在数据库中。

mysql jdbc jersey
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.