export default{
data () {
return {
current_tab_val:"1",
user: {
name: '',
password: ''
},
ruleInline: {
user: [
{ required: true, message: '请输入用户名', trigger: 'blur' }
],
password: [
{ required: true, message: '请输入密码.', trigger: 'blur' },
{ type: 'string', min: 6, message: '密码长度至少6位', trigger: 'blur' }
]
}
}
},
methods: {
handleSubmit(name) {
this.$refs[name].validate((valid) => {
if (valid) {
Axios.post('http://localhost:9090/user/login',this.user)
.then(res=>{
console.log('login.data=',res.data);
})
.catch(error=>{
})
this.$Message.success('Success!');
} else {
this.$Message.error('Fail!');
}
})
}
}
}
@RequestMapping(value = "/login",method = RequestMethod.POST)
public String login(@RequestParam String name, @RequestParam String password){
System.out.println("==============name============="+name);
AjaxResult result = new AjaxResult();
if(name.isEmpty()|| password.isEmpty()){
result.setSuccess(false);
result.setMsg("用户名或者密码不为空!");
return JSON.toJSONString(result);
}
User user = userService.findBy(name,password);
if(user!=null){
Map<String, Object> map = new HashMap<>();
map.put("user",user);
result.setData(map);
return JSON.toJSONString(result);
}else{
result.setSuccess(false);
result.setMsg("没有找到相应的用户!");
return JSON.toJSONString(result);
}
}
我使用@RequestParam或者@PathVariable都不行,请问有人知道如何解决吗
用
params
传递。