毕业设计爬坑记录

仅以此博客来记录做毕设过程中遇到的坑

后端

1.

报错

//Field XXX in XXXX required a bean of type XXXX that could not be found

Field udao in com.zyc.service.InitServiceImpl required a bean of type 'com.zyc.mapper.UserMapper' that could not be found.

但是检查XXX发现@Autowired自动注入并没有问题,mapper也是mybatisgen自动生成的,也没有问题。

发现原因

是扫描的包路径写错了,mapper没有扫描到(之前是复制粘贴上一个项目的哈哈哈)

解决办法

mapperScannerConfigurer.setBasePackage("com.zyc.mapper");

将扫描mapper路径改对即可

——————————————————————————   ————————————   —————

2.

报错

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary

初步判定是mysql驱动的问题,但是我项目是用的springboot,按道理不应该出问题

发现原因

经过百度发现,有许多人遇到一模一样的错误。网友给出的原因是最新的mysql驱动名称变了

以前的是

jdbc.driverClassName=com.mysql.jdbc.Driver

现在的是

jdbc.driverClassName=com.mysql.cj.jdbc.Driver

解决办法

改正配置中的名称即可

——————————————————————————   ————————————   —————

3.

报错

Exception in thread "main" java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

发现原因

经过百度,有许多人遇到一模一样的错误。网友给出的原因是这是在使用MySQL 8.0以上版本(MySQL连接驱动和版本都是8.0以上)的时候出现的问题错误

解决办法

我们需要在访问数据库的Url后面加上以下的语句即可:

?serverTimezone=GMT%2B8

比如我配置中原来是

url: jdbc:mysql://127.0.0.1:3306/loan?useUnicode=true&characterEncoding=utf-8

改成

url: jdbc:mysql://127.0.0.1:3306/loan?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8

——————————————————————————   ————————————   —————

4.

报错

java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [com.zyc.model.Goods]

发现原因

用redis时,model层必须实例化

解决办法

public class Goods implements Serializable{}

——————————————————————————   ————————————   —————

5.

没有报错,但是当java程序往redis中存数时,redis-cli(客户端)中查不到数字

发现原因

尝试了一下java程序可以从redis中取出数,又尝试了一下关闭redis服务器,java会报错找不到redis。

所以应该是java和redis客户端没有查询同一个redis数据库,并且java是可以成功往redis中存值的

在redis配置中

redis:
            host: 127.0.0.1
            port: 6379
            pass:
            maxIdle: 3000
            maxWait: 1000
            testOnBorrow: true
            database: 12 #    换数据库

那个database就是用哪个数据库,这里用的是12,而在redis客户端中,登陆redis,默认选择了数据库0,如果需要切换到其它数据库使用select 索引值,如select 1表示切换到索引值为1的数据库

解决方法

在redis-cli中select 12,使数据库和spring的redis配置中database后的数字相同

——————————————————————————   ————————————   —————

6.

报错

org.apache.ibatis.binding.BindingException: Parameter 'csid' not found. Available parameters are [arg1, arg0, param1, param2]

发现原因

在mapper层中取不到传来的参数值。当参数只有一个的时候可以取到并成功执行。当把两个参数的值在mapper层里写死的时候也可以成功运行。

相关代码如下

@Select({
            "select",
            "oid, userid, gid, otradetime",
            "from orders",
            "where csid = #{csid,jdbcType=INTEGER}",
            "and ostatus = #{ostatus,jdbcType=CHAR}"
    })
    @Results({
            @Result(column="oid", property="oid", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="userid", property="userid", jdbcType=JdbcType.INTEGER),
            @Result(column="gid", property="gid", jdbcType=JdbcType.INTEGER),
            @Result(column="otradetime", property="otradetime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Orders> approvalList(Integer csid,String ostatus);

解决办法

把随后一行的参数前加上@Param注解

List<Orders> approvalList(@Param("csid")Integer csid,@Param("ostatus")String ostatus);

——————————————————————————   ————————————   —————

7.

后端报错

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

前端报错

Failed to load resource: the server responded with a status of 403 ()
Failed to load http://localhost:8082/approval/list: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 403.

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Apr 05 19:25:22 CST 2019
There was an unexpected error (type=Bad Request, status=400).
Required request body is missing

发现原因

把debug时发现根本就没有走进去后端代码。(报的是跨域问题,但检查发现自己已经写@CrossOrigin来跨域了)

解决办法

把get改为post,包括@GetMapping改为@PostMapping,还有js的ajax中type从get改为post

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值