您好,登錄后才能下訂單哦!
最后使用ajax提交成功,下面是一些代碼,后面如果有時間再完善。
ajax:
function test(){
$.ajax({
type: "POST",
url: "test2",
contentType:"application/json",
data: '{"propTest":"test","list":[{"prop1":"a"},{"prop1":"b"}]}',
dataType: "json",
success: function(data){
console.log(data);
}
});
}
controller:
@ResponseBody
@RequestMapping(value="/test2",method=RequestMethod.POST)
public String hello2(@RequestBody TestList test){
System.out.println(test);
//value="/hello/{id}",
//@PathVariable(value="id") Integer id,
//@RequestParam(value="username") String username
//@CookieValue
return testBiz.getTest(1L);
}
spring配置:
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
bean信息:
public class TestList {
private String propTest;
public String getPropTest() {
return propTest;
}
public void setPropTest(String propTest) {
this.propTest = propTest;
}
private List<TestInner> list;
public List<TestInner> getList() {
return list;
}
public void setList(List<TestInner> list) {
this.list = list;
}
}
public class TestInner {
private String prop1;
public String getProp1() {
return prop1;
}
public void setProp1(String prop1) {
this.prop1 = prop1;
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。