1. 程式人生 > >ajax提交一個包含list的實體

ajax提交一個包含list的實體

lis ann list() end ctx date cati supported urn

/**
 * 添加
 */
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; } }

ajax提交一個包含list的實體