哪位大神可以指点一下:cors跨域细粒度设置不起作用啊

哪位大神可以指点一下:cors跨域细粒度设置不起作用啊!

如下图所示:

实际上,我后端控制器方法已经加好了注解了。

代码如下:

复制代码
package com.example.corsserver.controller;

import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
public class BookController {

    @PostMapping ("/")
    @CrossOrigin(value = "http://127.0.0.1:8081",maxAge = 1800,allowedHeaders = "*")
    public String addBook(String name){
        return "receive:"+name;
    }

    @DeleteMapping("/{id}")
    @CrossOrigin(value = "http://127.0.0.1:8081",maxAge = 1800,allowedHeaders = "*")
    public String deleteBookById(@PathVariable Long id){
        return String.valueOf(id);
    }
}

下面代码是前端页面的代码:

复制代码
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery.js" ></script>


</head>
<body>
<div id="contentDiv">

</div>

<div id="deleteResult"></div>

<input type="button" value="提交数据" onclick="getData()"><br>
<input type="button" value="删除数据" onclick="deleteData()"><br>
<script>
    function deleteData(){
        $.ajax({
            url:'http://127.0.0.1:8080/book/99',
            type:'delete',
            success:function (msg){
                $("#delteResult").html(msg);
            }
        })
    }
    function getData(){
        $.ajax({
            url:'http://127.0.0.1:8080/book',
            type:'post',
            data:{name:'三国演义'},
            success:function (msg){
                $("#contentDiv").html(msg);
            }
        })
    }
</script>
</body>
</html>

静态页面,2个按钮。

哪个大神可以指导一下呢。这种情况,是什么原因引起的?

相关推荐
shark22222226 小时前
能懂!基于Springboot的用户增删查改(三层设计模式)
spring boot·后端·设计模式
IGAn CTOU7 小时前
王炸级更新!Spring Boot 3.4 正式发布,新特性真香!
java·spring boot·后端
indexsunny8 小时前
互联网大厂Java面试实战:核心技术与微服务架构在电商场景中的应用
java·spring boot·redis·kafka·maven·spring security·microservices
海兰9 小时前
【第3篇-续】多模型多模态项目实现示例(增加OpenAI通用适配)附源代码
java·人工智能·spring boot·alibaba·spring ai
SarL EMEN10 小时前
海康威视摄像头ISUP(原EHOME协议) 摄像头实时预览springboot 版本java实现,并可以在浏览器vue前端播放(附带源码)
java·前端·spring boot
ccice0110 小时前
全面掌握Spring Boot + MyBatis + Maven + MySQL:从开发到部署的后端技术详解
spring boot·maven·mybatis
QQ227923910211 小时前
Java springboot基于微信小程序的智慧旅游导游系统景点门票酒店预订(源码+文档+运行视频+讲解视频)
java·spring boot·微信小程序·maven·vuejs
是宇写的啊12 小时前
SpringBoot日志
java·spring boot·spring
消失的旧时光-194312 小时前
Spring Boot + MyBatis 从 0 到 1 跑通查询接口(含全部踩坑)
spring boot·后端·spring·mybatis
希望永不加班13 小时前
SpringBoot 中 AOP 实现多数据源切换
java·数据库·spring boot·后端·spring