在springmvc.xml文件中添加如下配置
<!-- 防止请求跨域 -->
<mvc:cors>
<mvc:mapping path="/**" allowed-origins="*"
allow-credentials="true" max-age="1800" allowed-methods="GET,POST,OPTIONS" />
</mvc:cors>
转载:https://blog.csdn.net/weixin_41558061/article/details/101097814?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.control&dist_request_id=&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.control