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

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

相关推荐
用户35218024547510 小时前
🎆从 Prompt 到 Skill:让 Spring AI Agent 学会"装新技能"
人工智能·spring boot·ai编程
用户3521802454753 天前
当 Prompt 学会"热更新":Spring Boot × Nacos3 AI 实战
java·spring boot·ai编程
昵称为空C3 天前
手撸一个动态 SQL 执行引擎:不重启服务,在线增删改查任意数据库
spring boot·后端
霸道流氓气质4 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
于先生吖4 天前
SpringBoot对接大模型开发AI命理测算系统:八字排盘与AI解析接口源码全解
人工智能·spring boot·后端
Flittly4 天前
【AgentScope Java新手村系列】(10)实战-多Agent天气助手
java·spring boot·spring
星落zx5 天前
Spring Boot 多模型集成:优雅调用全球主流大模型
人工智能·spring boot·chatgpt
一杯奶茶¥5 天前
水果销售网站 CRM客户信息管理系统 超市管理系 酒店管理系统 健身房管理系统 在线音乐网站 校园招聘系统
java·vue.js·spring boot·mysql·spring·java项目
进阶的小名5 天前
Spring Boot SSE + Nginx 配置:解决 EventSource 不实时返回、连接超时、流式响应被缓冲问题
spring boot·后端·nginx