1. Form 标签:
<form:form method="post" style="height:100px;width:1600px">
更新<input type="hidden" name="_method" value="put">
更新<input type="area" name="updateLoraParam" id="updateLoraParam" multiple="multiple" style="height:100px;width:1600px"></input>
更新 <input type="button" id="updateLora" name="updateLora" value="更新Lora" width="100px"/><br/>
更新Lora结果:<input type="text" name="updateLoraRet" id="updateLoraRet" multiple="multiple" style="height:100px;width:1600px"></input>
</form:form>
2. ajax的编写:
$("#updateLora").click(function (){
var updatejason = $("#updateLoraParam").attr("value");
$.ajax({
url: "/lorartu/lorainfo/",
type: "POST",
async: false,
data: {'_method':'put', 'upLorainfo': updatejason},
dataType: "text",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
success: function (data) {
console.log(data);
$("#updateLoraRet").attr("value", data);
}
});
});
3.springmvc的控制器写法:
@RequestMapping(value = "/lorainfo/", method = RequestMethod.PUT, produces = "application/json;charset=UTF-8")
@ResponseBody
public String UpdateUser(@RequestParam("upLorainfo") LoraRtu upLorainfo) throws IOException {
boolean bLoraRtu = loraRtuService.updateById(upLorainfo);
return bLoraRtu ? "R:0": "R:1";
}
注意事项:
1. 第二步中的data参数中的updatejason 为:{"lrid":4, "commVersion":"v13.3.33","lrPort":21233,"urlOrIp":"www.rola.com","lrName":"用户","remark1":"管理用户","latitude":1212.2,"longitude":22.32,"cycle":23,"type":"123","snr":null,"rssi":null,"connectDate":null,"deviceNo":nul}
其模拟了Form表单的值的收集。