简体   繁体   English

SPRING框架:客户端发送的请求在语法上不正确

[英]SPRING framework: The request sent by the client was syntactically incorrect

@RequestMapping(value = "/invoice", method = RequestMethod.POST)
    public String submitInvoice(HttpServletRequest request, 
            @RequestParam("clients") int clientId,
            @RequestParam("invoice_date") String invoice_date, 
            @RequestParam("invoice_due_date") String invoice_due_date, 
            @RequestParam("status") String status, 
            @RequestParam("payment_method") String payment_method, 
            @RequestParam("currency") String currency, 
            @RequestParam("description") String description, 
            @RequestParam("quantity") String quantity, 
            @RequestParam("price") String price, 
            @RequestParam("total") String lineTotal) {

        if(!hasRole(request, "ROLE_USER")){
            return "403";
        }

        long invoiceId = 0;

        DBManager.createInvoice(clientId, invoice_date, invoice_due_date, status, payment_method, currency);
        DBManager.invoiceDescription(invoiceId, description, quantity, price, lineTotal);



        return "redirect:/invoices/page/1";
    }

Database Manager Below 下面的数据库管理器

public static long createInvoice(
        int clientId, String invoice_date, String invoice_due_date, 
        String status, String payment_method, String currency){

        Connection dbConnection = null;
        PreparedStatement preparedStatement = null;

        long invoiceId = 0;

        //String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());


        String sql = "INSERT INTO invoice"
                + "(invoiceId, clientId, invoice_date, invoice_due_date, status, payment_method, currency) VALUES"
                + "(NULL,?,?,?,?,?,?)";

        try {

            dbConnection = getDBConnection();

            preparedStatement = dbConnection.prepareStatement(sql);

            preparedStatement.setInt(1, clientId);
            preparedStatement.setString(2, invoice_date);
            preparedStatement.setString(3, invoice_due_date);
            preparedStatement.setString(4, status);
            preparedStatement.setString(5, payment_method);
            preparedStatement.setString(6, currency);

            preparedStatement.executeUpdate();

            System.out.println("You have successfully created an invoice record");

            PreparedStatement getLastInsertId = dbConnection.prepareStatement("SELECT LAST_INSERT_ID()");
            ResultSet rs = getLastInsertId.executeQuery();
            if(rs.next())
            {
                invoiceId = rs.getLong("last_insert_id()");

                System.out.println("Last invoiceId inserted: " + invoiceId);

            }

        } catch (SQLException e){

            System.out.println(e.getMessage());

        }
        return invoiceId;
    }

public static void invoiceDescription(
        long invoiceId, String description, String quantity, 
        String price, String lineTotal){

        Connection dbConnection = null;
        PreparedStatement preparedStatement = null;


        //String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());


        String sql = "INSERT INTO invoice_description"
                + "(descId, invoiceId, description, quantity, price, total) VALUES"
                + "(NULL,?,?,?,?,?)";

        try {

            dbConnection = getDBConnection();

            preparedStatement = dbConnection.prepareStatement(sql);

            preparedStatement.setLong(1, invoiceId);
            preparedStatement.setString(2, description);
            preparedStatement.setString(3, quantity);
            preparedStatement.setString(4, price);
            preparedStatement.setString(5, lineTotal);

            preparedStatement.executeUpdate();

            System.out.println("You have successfully added descriptions to invoice");


        } catch (SQLException e){

            System.out.println(e.getMessage());

        }
    }

I am getting the following message for the code above: 对于以上代码,我收到以下消息:

'The request sent by the client was syntactically incorrect.' .

I am trying to insert into multiple tables. 我正在尝试插入多个表。 If I remove DBManager.invoiceDescription it will insert the first part to the invoice table very well without errors, but when I add the invoiceDescription part, it doesn't insert anything. 如果删除DBManager.invoiceDescription它将很好地将第一部分插入发票表中,而不会出现错误,但是当我添加invoiceDescription部分时,它不会插入任何内容。 Please help :) 请帮忙 :)

Error "The request sent by the client was syntactically incorrect." 错误"The request sent by the client was syntactically incorrect." means that your request was not correctly formatted. 表示您的请求格式不正确。

I see that all your request parameters are required, so if at least one of them is missing you'll get this error. 我看到您的所有请求参数都是必需的,因此,如果其中至少有一个丢失,则会出现此错误。 Make sure that you are sending all your request parameters, or if you want sometimes to send some of them, you can make them not mandatory: 确保您正在发送所有请求参数,或者如果您有时希望发送其中一些参数,则可以使它们不是必需的:

@RequestParam(value = "clients", required = false)

In this case if you make them all not mandatory, you can chose which params to send. 在这种情况下,如果不强制要求所有参数,则可以选择发送哪些参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring形式:客户端发送的请求在语法上不正确() - Spring form : The request sent by the client was syntactically incorrect () spring mvc - 客户端发送的请求在语法上是不正确的 - spring mvc - The request sent by the client was syntactically incorrect Spring:客户端发送的请求在语法上是不正确的() - Spring: The request sent by the client was syntactically incorrect () 客户端发送的请求在语法上不正确 - The request sent by the client was syntactically incorrect Spring MVC文件上传-客户端发送的请求在语法上不正确 - Spring MVC File Upload - The request sent by the client was syntactically incorrect Spring MVC-上传文件显示客户端发送的请求在语法上不正确 - Spring MVC - upload file shows The request sent by the client was syntactically incorrect 客户端发送的请求在语法上是不正确的。 在春天使用@RequestParam - The request sent by the client was syntactically incorrect. using @RequestParam in spring 客户端发送的请求在语法上不正确。 在@ManyToOne关系中休眠,春季 - The request sent by the client was syntactically incorrect. in @ManyToOne relation Hibernate, Spring 使用Spring MVC进行CRUD时出现错误“客户端发送的请求在语法上不正确” - Error “The request sent by the client was syntactically incorrect” when CRUD with Spring MVC 客户端发送的请求在spring mvc,ajax中在语法上不正确 - The request sent by the client was syntactically incorrect in spring mvc, ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM