SpringBoot问题1

运行dao层类测试遇到问题

对ProductCategoryRepository类测试

1.运行saveTest

SpringBoot问题1
原因:ProductCategory实体类中的id是自动生成的,生成方式没有指定
SpringBoot问题1
解决方法:
SpringBoot问题1

2.数据库插入中文乱码

原因:
SpringBoot问题1中的中文编码出错
解决:
SpringBoot问题1

3.对更新进行测试时,实体类中添加时间,运行报错

SpringBoot问题1
解决:去对应的实体类中找到相应的属性,查看属性前的类型

对ProductInfoRepository类测试

4.测试save报错:

SpringBoot问题1
异常抛出:

SpringBoot问题1
翻译:
原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:“字段列表”中的未知列“productinf0_u.product_description”
说product_description属性在数据表中找不到

解决方法
先检查数据表里面是否由这个字段也就是属性
SpringBoot问题1
SpringBoot问题1
没有此属性在数据表中添加属性
SpringBoot问题1
再重新运行test,最后运行成功

findByProductStatusTest此方法测试前得保证数据表里边有信息

运行Service层类测试遇到问题

1.测试运行报错:

SpringBoot问题1
翻译:
通过字段“categoryService”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:没有“com.hdc.sell.service.impl.CategoryServiceImpl”类型的限定bean可用:至少需要1个符合autowire候选的bean。依赖项批注:{@org.springframework.beans.factory.annotation.Autowired(必需=true)}
SpringBoot问题1
解决方法:
要测试类的开头加SpringBootTest注解
SpringBoot问题1
springboot使用单元测试详细解说
https://my.oschina.net/zjllovecode/blog/1605981

2.在ProductServiceImpl中调用枚举类里的方法调用不出

SpringBoot问题1
原因是:枚举类里面没有getter方法
解决方法:
到ProductStatusEnum中最上边添加自动生成getter方法的注解
SpringBoot问题1
自动生成注解时用到idea中的一个小插件lombok,idea中下载小插件就可以用了,安装小插件点下面链接
https://blog.****.net/YaNyAn2_/article/details/105599364

3.编写ProductServiceImplTest时出错:

SpringBoot问题1
原因:
创建ProductServiceImpl类时没有将他交由spring容器管理。所以也不能用spring对productService对象进行注入
解决方法:
到ProductServiceImpl中在最前面加上@Service,就是将ProductServiceImpl交由spring容器管理
SpringBoot问题1

4.写查找方法报错

SpringBoot问题1
解决:
加入双引号即可
SpringBoot问题1

5.分页测试出现问题

SpringBoot问题1
原因:
当前版本当中Jpa当中PageRequest取实例化request分页对象方式已经过时了
解决:
新的方法:通过调用PageRequest里面的of方法来完成对分页对象request的初始化
SpringBoot问题1