调试接口==(关于前端传递list的json后端如何接收)

来源:互联网 发布:ubuntu 更换系统语言 编辑:程序博客网 时间:2024/06/05 17:34

今天遇到一个前端传递list的问题,一般传递fom表单一类的springMVC都会自动封装,但是list却不行。这里做一个笔记。

一、已经定义好的实体类

package com.huayi.soa.domain.materiel;public class MaterielPosition {    /**     * ID编码     */    private Integer id;     /**     * 物料ID     *///    @NotNull(groups={MaterielPositionController.AddMaterielPosition.class})    private Integer materielId;     /**     * 入库单ID     *///    @NotNull(groups={MaterielPositionController.AddMaterielPosition.class})    private Integer entryId;     /**     * 大队单ID     */    private Integer applyId;     /**     * 出货单ID     */    private Integer shipmentId;     /**     * 小队单ID     */    private Integer teamId;     /**     * 产品流水号起     */    private String number;     /**     * 数量     *///    @NotNull(groups={MaterielPositionController.AddMaterielPosition.class})    private Integer count;     /**     * 仓库ID     *///    @NotNull(groups={MaterielPositionController.AddMaterielPosition.class})    private Integer storage;     /**     * 货架号     *///    @NotNull(groups={MaterielPositionController.AddMaterielPosition.class})    private Integer shelf;     /**     * 货架格子 4格     *///    @NotNull(groups={MaterielPositionController.AddMaterielPosition.class})    private Integer grid;     /**     * 车辆ID     */    private Integer vehicle;     /**     * 大队ID     */    private Integer brigade;     /**     * 小队id     */    private Integer team;     /**     * 状态(字典)     */    private Integer status;     getter和setter方法}  

二、新建一个实体类(用于此次封装)重点

import java.util.List;/** * 功能:将MaterielPosition对象封装到list中,便于前台传递过来 * @author mch * */public class MaterielPostionList {private List<MaterielPosition> materielPostionList;public List<MaterielPosition> getMaterielPostionList() {return materielPostionList;}public void setMaterielPostionList(List<MaterielPosition> materielPostionList) {this.materielPostionList = materielPostionList;}public MaterielPostionList(){}public MaterielPostionList(List<MaterielPosition> materielPostionList) {super();this.materielPostionList = materielPostionList;}}

三、controller类

@RequestMapping("materielPosition")public ResultViewModel addMaterielPosition( @RequestBody MaterielPostionList materielPositionList){materielPositionService.insertMaterielPosition(materielPositionList);return new ResultViewModel(CodeConstant.SUCCESS,CodeConstant.SUCCESS_MSG);}
注意这里用@RequestBody接收参数、如果不行,可以使用@valadate和@RequestrianBody一起使用

四、前端调试


接下来、就可以填写参数调试了。

阅读全文
0 0
原创粉丝点击