axios傳送請求
阿新 • • 發佈:2020-12-17
import com.alibaba.fastjson.JSON; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping public class UpdateTimeController { @Autowired TimeMapper timeMapper; public String queryEndTime(@RequestBody String id){//傳入後端為json物件{"id":"12345678"} TimeDO timeBean = JSON.parseObject(id,TimeDO.class);
TimeDO time = TimeMapper.getTimeByReqId(timeBean.getId()); return JSON.toJSONString(time);
} }
public class TimeDo { private String id; private String endTime; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getEndTime() { return endTime; } public void setEndTime(String endTime) { this.endTime = endTime; } }
new Vue({ el:'#app', data(){ return{ time:{ id:'', endTime:'' } } }, methods:{ queryEndTime:function(){ axios({ url:'/queryEndTime', method:'post', data:{ id:this.time.id //輸入框輸入的id值 } }).then(response=>{ this.time = response.data; console.log(this.time.endTime); }); } } });
requestId