哪位大神可以指点一下: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个按钮。

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

相关推荐
Flittly1 天前
【雕虫大技】Agent 动态 Skill 供应链安全加固(三):输出校验与治理闭环实战
java·spring boot·spring
小强库计算机毕业设计2 天前
基于 Spring Boot + Vue3 的校园管理系统
java·spring boot·后端·项目实战·管理系统·技术分享·校园管理系统实战
毕设单片机2 天前
顺顺救助站流浪动物领养系统的设计与实现46649----SpringBoot + Vue.js + MySQL|领养审核、寻宠发布、救助站点与动物论坛协同
java·spring boot·管理系统·流浪动物
云烟成雨TD2 天前
Micrometer 系列【63】统一观测:基于 Spring Boot 的生产级演示案例 | 基于 OTLP 集成 Prometheus + Jaeger
spring boot·云原生·prometheus
csdn2015_2 天前
springboot +mybatis 查询myql开启程序级别缓存
spring boot·缓存·mybatis
chuan.bai2 天前
Java RAG 实战(第 8 篇):Spring Boot RAG 查询 API
java·spring boot·贪心算法
vx-程序开发2 天前
springboot旅游推介平台---附源码24175
java·spring boot·python·spring cloud·eclipse·django·idea
小蒜学长2 天前
“喵汪联盟”宠物领养系统的设计与实现(代码+数据库+LW)
java·spring boot·后端·宠物
xbgRS2 天前
springboot的自动装配
java·spring boot
嘻哈∠※2 天前
0061基于 SpringBoot 的投稿与稿件处理系统设计与实现
java·spring boot·后端