本文章仅用来记录课设所发生的错误,SpingBoot和js速成,因此遇到很多问题,仅具有参考性。
报错:
Access to XMLHttpRequest at ‘http://localhost/login/hello’ from origin ‘http://127.0.0.1:5500’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
此问题为跨域问题
后台解决方法是在Controller类前加上@CrossOrigin注解
@CrossOrigin
@RestController
@RequestMapping("/login")
public class LoginController {
@Autowired
private ILoginService iLoginService;
private LoginDao loginDao;
@RequestMapping("{Sno}")
public ResponseEntity<R> getById(@PathVariable String Sno){
R r = new R(true,iLoginService.getById(Sno));
return new ResponseEntity<>(r,HttpStatus.OK);
}
}