V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kyoma
V2EX  ›  问与答

江湖救急, 这里为什么报空指针错误啊?顺便 uniapp 怎么传 formdata 呢 谢谢

  •  
  •   kyoma · Jun 5, 2020 · 1547 views
    This topic created in 2156 days ago, the information mentioned may be changed or developed.
    data() {
    			return {
    				searchTag:'',
    				test:{
    					uuid:'7b7ecc47d5af40c8a72f0532c60a94e0',
    					type:'1',
    				}
    			} 
    		},
    		methods: {
    			queryTspMainByType()
    			{
    				uRequestJson({
    					url:'tSpMain/queryTspMainByType',
    					data:this.test,
    					method:'POST',
    					success:(res)=>{
    						console.log("res",res)
    					},
    				})
    			}
    		},
    

    这是接口

    @RequestMapping("/queryTspMainByType")
    	public R queryTspMainByType(@RequestBody ParamMap map) {
    		return mainService.queryTspMainByType(map.getInt("type"), map.getStr("uuid"));
    	}
    

    然后后台报空指针异常 uniapp 没办法直接 new FormData,我从网上查询的说是要改 header,但是还是不行。

    4 replies    2020-06-05 17:50:56 +08:00
    zachlhb
        1
    zachlhb  
       Jun 5, 2020 via Android
    改 header 的 contentType 为 application/x-www-form-urlencoded
    kyoma
        2
    kyoma  
    OP
       Jun 5, 2020
    @zachlhb 谢谢 OK 了
    FieldFarmer
        3
    FieldFarmer  
       Jun 5, 2020
    把 this.test 转一下 json 格式也是可以的
    FieldFarmer
        4
    FieldFarmer  
       Jun 5, 2020
    #3 然后 map 改成用对象接收
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2647 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 03:14 · PVG 11:14 · LAX 20:14 · JFK 23:14
    ♥ Do have faith in what you're doing.