山东大学软件学院创新实训——项目记录(十一)

零、前言

本次记录主要是项目的前后端对接时遇到的问题的处理,是比较常见的但是很重要的错误,故在此记录解决方案。

一、跨域错误

错误描述:

Access to fetch at ‘http://localhost:9090/user/list’ from origin ‘http://localhost:8080’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

如何解决?

  1. 跨域问题通常在前端与后端在不同域名或端口间通信时发生。浏览器出于安全考虑,默认禁止这种跨域请求。
  2. @CrossOrigin:这是springboot提供的跨域请求注解
  3. 使用 CORS (跨域资源共享)
    CORS 是一种允许服务器指定哪些域名可以访问资源的机制。你可以在服务器端配置 CORS 头来允许跨域请求。

二、Mybatis官网示例

https://mybatis.net.cn/getting-started.html

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.springboot.mapper.UserMapper">
    <insert id="save">
        insert into user(name,username,age,sex,phone,address)
        values(#{name},#{username},#{age},#{sex},#{phone},#{address})
    </insert>

</mapper>

错误:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.springboot.mapper.UserMapper.listUsers

解决:配置mapper.xml

mybatis:
mapper-locations: classpath:mapper/*.xml

三、axios接口传递错误

Network Error at
XMLHttpRequest.handleError
(webpack-internal:///./node_module

错误原因:

“/user/delete”+id改为"/user/delete/“+id
具体解释就是将请求参数放在url的话要在”/"之后

查看错误原因代码:

this.catch((err) => {
    console.log(err)
})

四、常见的空引用错误

java.lang.IllegalArgumentException: Source must not be null

错误原因:写代码时没考虑异常情况;

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值