/**
* 全局设置
*
*/
@Configuration
public class CustomCorsConfiguration2 extends WebMvcConfigurerAdapter {

        @Override
        public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**").allowedOrigins("http://localhost:8080");
    }
}


/**
*细粒度配置
* 
*/
@RestController
@RequestMapping(value = "/api", method = RequestMethod.POST)
public class ApiController {

    @CrossOrigin(origins = "http://localhost:8080")
    @RequestMapping(value = "/get")
    public HashMap<String, Object> get(@RequestParam String name) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("msg", "跨域测试");
        map.put("name", name);
        return map;
    }
}

 

相关文章:

  • 2021-11-22
  • 2022-01-07
  • 2021-12-01
  • 2021-12-13
  • 2021-07-26
  • 2021-08-25
  • 2022-12-23
猜你喜欢
  • 2021-12-19
  • 2022-12-23
  • 2022-03-08
  • 2021-10-11
  • 2021-06-19
  • 2021-12-06
相关资源
相似解决方案