2017-03-10 2 views
0

複数の文字列を春に送信するにはどうすればよいですか?複数のStringを配列に変換すると送信できますが、複数のStringを送信しようとすると機能しません。 Failed to load resource: the server responded with a status of 401()は春に 私が受信しよう::春に私は私が受け取る複数のStringをSpringに送信するには?

function sendCustomerInfo() { 

    var nameCustomerForSend = $("#NickNameCustomerForSend").val(); 
    var phoneCustomerForSend = $("#PhoneCustomerForSend").val(); 
    var emailCustomerForSend = $("#EmailCustomerForSend").val(); 
    var addressCustomerForSend = $("#descriptionCustomerForSend").val(); 

    console.log("Name: " + nameCustomerForSend + " Address: " + addressCustomerForSend + " Phone: " + phoneCustomerForSend 
     + " Email: " + emailCustomerForSend); 


    $.ajax({ 
     headers: { 
      "Accept": "application/json", 
      "Content-Type": "application/json" 
     }, 
     type: "POST", //это типа method 
     data: {NickName:nameCustomerForSend, Phone:phoneCustomerForSend, Email:emailCustomerForSend, 
      description:addressCustomerForSend}, 
     url: '/showAll/customerInfo', 
     success: function (msg) { 
      window.location.href = "/showAll" 
     } 
    }); 
} 

を(などの分割、新しいString、)より多くのコードを使用する必要がありますbecouseではなく、良いアイデアを春にアレイを送る

@RequestMapping(value = "/showAll/customerInfo", method = { RequestMethod.POST} 
     , produces = MediaType.APPLICATION_JSON_VALUE) 
public ModelAndView showAllForCustomer(@RequestParam(value = "NickName")String name, 
             @RequestParam(value = "Phone")String phone, 
             @RequestParam(value = "description")String addressDelivery, 
             @RequestParam(value = "Email")String email) { 
    System.out.println("Name: " + name + " Phone: " + phone + " Address: " + addressDelivery + " Email: " + email); 
    ModelAndView modelAndView = new ModelAndView(); 
    return modelAndView; 

} 
ポストおよびアプリケーション/ JSON型のデータと

答えて

0

使用@RequestBody あなたは

public ModelAndView showAllForCustomer(@RequestBody CustomerDto dto){ 
    ............ 
} 
ようshowAllForCustomer に指定されているすべてのパラメータを持つDTOを作成します。
関連する問題