在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java/ springmvc controller參數(shù)值是類(lèi)的時(shí)候axios如何傳參?

springmvc controller參數(shù)值是類(lèi)的時(shí)候axios如何傳參?

@RequestMapping(value = "/save", method = RequestMethod.POST)
    public String save(@RequestParam Teacher teacher, @RequestParam List<Label> labels){
        AjaxResult result = new AjaxResult();
        System.out.println("==============teacher===========");
        System.out.println(teacher.toString());

        System.out.println("==============labels===========");
        System.out.println(labels);
        result.setSuccess(true);
        return JSON.toJSONString(result);
    }
data () {
    return {
        label:{
            name:'',
            list:[]
        },
        ruleInline: {
            name: [
                { required: true, message: '請(qǐng)輸入老師姓名', trigger: 'blur' }
            ],
            phone: [
                { required: true, message: '請(qǐng)輸入手機(jī)號(hào)', trigger: 'blur' }
            ]
        },
        teacher: {
            name: '',
            nikename: '',
            phone: '',
            email: '',
            sex: 1,
            age: 0,
            teachAge: 0,
            aptitudefile: '',
            school: '',
            country: '',
            goodat: '',
            aboutme:''
        }
    }
    },
    
this.$post('http://localhost:9090/teacher/save',{
                            teacher:this.teacher,
                            labels:this.label.list
                        })
                        .then(res=>{
                            console.log('res=',res)
                        })
                        .catch(err=>{

                        })

clipboard.png

回答
編輯回答
毀了心

類(lèi)的話不要用RequestParam,用RequestBody,會(huì)自動(dòng)從Json解析成類(lèi),不同類(lèi)型的兩個(gè)參數(shù)的話可以在設(shè)計(jì)一個(gè)參數(shù)類(lèi)。

class Param{
  private Teacher teacher;
  private List<Label> labels;
  //需要無(wú)參數(shù)的構(gòu)造函數(shù)和兩個(gè)字段的getter和setter
}
...
public String save(@RequestBody() Param param){
 Teacher teacher = param.getTeacher();
List<Label> labels = params.getLabels();
return "Ok";
}
2017年11月18日 04:20