/** * 添加 */ function insertPsas() { var psasName = $(‘#psasName‘).val(); if(materials[0]==null){ layer.alert("请选择视频!"); return; }else if(materials[1]==null || materials[2]==null){ layer.alert("请选择图片!"); return; } $.ajax({ url : ctx + ‘/psas/insertPsas‘, data : "{\"psasName\":\""+psasName+"\",\"materialList\":"+JSON.stringify(materials)+"}", type : ‘post‘, async : true, dataType : "json", contentType: "application/json", success : function(data) { if (data.msg == ‘00‘) { queryDevice(); layer.alert(‘提交成功!‘, { icon : 1, skin : ‘layer-ext-moon‘ }); } else if (data.msg == ‘02‘) { layer.alert(‘提交失败!‘, { icon : 2, skin : ‘layer-ext-moon‘ }); } } }); }
@UserAnnotation(methodName = "添加公益广告", markName = "order.psas.insertPsas") @RequestMapping(value = "/insertPsas", method = { RequestMethod.POST, RequestMethod.GET }) public void insertPsas(HttpServletRequest request, HttpServletResponse response,@RequestBody Psas psas) throws Exception { JSONObject jsonObject = new JSONObject(); try { psas.setTemplateId(3L); psas.setCreateTime(DateUtil.getCurrDateTime()); psas.setValid(1); psas.setVersion(1L); this.psasService.insertPsas(psas); msg = Constants.SCUUESS; } catch (Exception e) { log.error("insertDevice:" + e); msg = Constants.FAIL; } jsonObject.accumulate("msg", msg); responseSendMsg(response, jsonObject.toString()); }
xml <bean id="mappingJackson2HttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json</value> <!--自定义处理MediaType--> <value>text/json</value> </list> </property> </bean>
实体
public class Psas extends BaseModel { private Long id; private List<Material> materialList; public List<Material> getMaterialList() { if (materialList == null) { materialList = new ArrayList<Material>(); } return materialList; } public void setMaterialList(List<Material> materialList) { this.materialList = materialList; } }
原文:http://www.cnblogs.com/cynszb/p/7767985.html