记MyBatis和MySQL中遇到的一些小问题

问题:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'top.kittygirl.xdtoutiao.InitDatabaseTests': Unsatisfied dependency expressed through field 'userDAO'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'top.kittygirl.xdtoutiao.dao.UserDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
解决:
测试类的前面加上
@RunWith(SpringRunner.class)
@SpringBootTest
参考资料:
https://zhidao.baidu.com/question/1992834174150299427.html
https://zhuanlan.zhihu.com/p/26794187
 
问题:
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
解决:
数据库没有打开

问题:
org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #2 of class path resource [init-schema.sql]: CREATE TABLE `user` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(64) NOT NULL DEFAULT '', `password` VARCHAR(128) NOT NULL DEFAULT '', `salt` VARCHAR(32) NOT NULL DEFAULT '', `head_url` VARCHAR(256) NOT NULL DEFAULT '', PRIMARY KEY ('id'), UNIQUE KEY `name` (`name`) )ENGINE = InnoDB DEFAULT CHARSET = utf8; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''id'), UNIQUE KEY `name` (`name`) )ENGINE = InnoDB DEFAULT CHARSET = utf8' at line 1
解决:
单引号''与 反单引号``用错
在MySQL中``是为了区分MYSQL的保留字与普通字符而引入的符号,如果表名、字段名中没有保留关键字,则可以省略,因此尽量不要使用反单引号
参考资料:

问题:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'like_count' in 'class top.kittygirl.xdtoutiao.model.News'
解决:
在DAO中的sql语句中传入的参数#{}不是数据库表中定义的量like_count,而是model中定义的变量名likeCount,MyBatis会将model中定义的变量和sql中的参数联系起来
参考资料:

问题:
org.springframework.jdbc.BadSqlGrammarException:  
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'tiket' in 'field list'
### The error may involve top.kittygirl.xdtoutiao.dao.LoginTicketDAO.addTicket-Inline
### The error occurred while setting parameters
### SQL: insert into  login_ticket (  user_id, expired, status, tiket  ) values (?,?,?,?)
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'tiket' in 'field list'
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'tiket' in 'field list'
解决:
拼写错误



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值