1:react使用axios调用
import axios from 'axios'
let url ='http://localhost:8080/TEST/R/logon/login.do' let myData = new FormData(); // 因为是FormData,所以不需要指定Content-Type myData.append("loginname",values.userName); myData.append("password",values.password); axios.post(url, myData) .then(function (response) { console.log(response); if(response.state=1) { // hashHistory.push('/home'+'/'+ values.userName) // hashHistory.push({pathname:'/home',query:{name:values.userName}}) hashHistory.push({pathname:'/home',state:{param:values.userName}}) } else { this.setSatate({loginstate:'2'}) } }) .catch(function (error) { console.log(error); })
2:后台
@RestController @RequestMapping(value = "/R/logon") public class RestLogonController { @RequestMapping(value = "/login.do", method = RequestMethod.POST) @ResponseBody public Map<String, String> loginAccount(ModelMap model, HttpServletRequest request, HttpServletResponse response, LogonBean bean) throws Exception { ICertificationAuthority certificationAuthority = getCertificationAuthorityStrategy(); CertificationAuthorityResultBean result = certificationAuthority.getCertificationAuthorityResult(bean, request); Map<String, String> res = new HashMap<String, String>(); if (result.isErrorFlag()) { res.put("state", "0"); } else { res.put("state", "1"); } return res; }