json
object
からjavascript
をSpring controller
に送信しようとしています。私はangularJs $http post
を使っています。私はkey
をobejct
として送信したときにlastNameをnull
としています。しかし、string
をハードコードされた値として送信すると、その値はcontroller
に表示されます。ここでcontroller
コードは:
@RequestMapping(value="/edit", method= RequestMethod.POST)
@ResponseBody
public void editInformation(@RequestBody UserDetails userDetails){
LOGGER.debug("THE LASTNAME IS: "+userDetails.getLastName());
//codes.....
}
ここangularJsコードは:JSONはヌルとしてuserDetails.getLastName()
を返すよう
$fieldProperty =$(this).attr("name");
$inputValue =$(this).val();
$http.post("/app/edit", {$fieldProperty : $inputValue}).success(function(result){
alert("Success "+result)
}).error(function(data, status){
//$log.info("The error is: "+data+ " and the error status code is: "+status)
alert("failure"+" and the data is: "+data+ " and the stis "+status)
});
は{$fieldProperty : $inputValue}
を送信します。ただし、{"lastName" : $inputValue}
を送信すると適切な値が返されます。 alert($fieldProperty)
で確認しましたが、それはlastName
を返します。 私はGoogle Gson
ライブラリを使用しています。
ここには何かがありますか?私はあなたの助けに感謝します。ありがとうございました。