当前位置: 首页 > news >正文

用asp做网站有哪控件如何免费做网站推广的

用asp做网站有哪控件,如何免费做网站推广的,上海做网站好的公司有哪些,网站设计公司 上海文章目录 一,product模块整合mybatis-plus1,引入依赖2,product启动类指定mapper所在包3,在配置文件配置数据库连接信息4,在配置文件中配置mapper.xml映射文件信息 二,单元测试1,编写测试代码&am…

文章目录

  • 一,product模块整合mybatis-plus
    • 1,引入依赖
    • 2,product启动类指定mapper所在包
    • 3,在配置文件配置数据库连接信息
    • 4,在配置文件中配置mapper.xml映射文件信息
  • 二,单元测试
    • 1,编写测试代码,执行单元测试
  • 三,错误记录
    • 1,单元测试失败初步排查
    • 2,缺失驱动类依赖

本节的主要内容是product模块整合mybatis-plus,并进行单元测试,测试微服务基本CRUD功能。

一,product模块整合mybatis-plus

1,引入依赖

使用mybatis-plus,需要引入依赖。这一步在上一节已经在common模块引入,这里只做记录,无需再次引入。

		<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.2.0</version></dependency>

2,product启动类指定mapper所在包

mybatis会根据Mapper代码文件中定义的接口生成代理类,需要告知Mapper接口文件所在的包。

MapperScan的作用是在应用的配置类中指定一个或多个包,Spring将会自动查找这些包下所有的接口,并将它们注册为Spring Bean。

意味着在这些包中的所有标注了@Mapper的接口都会被自动识别和实例化,而无需在Spring的XML配置文件中显式声明每一个Mapper。

@MapperScan(basePackages = "com.atguigu.gulimall.product.dao")

在这里插入图片描述

3,在配置文件配置数据库连接信息

在这里插入图片描述

spring:datasource:username: rootpassword: rooturl: jdbc:mysql://192.168.56.10:3306/gulimall_pms

4,在配置文件中配置mapper.xml映射文件信息

在这里插入图片描述

mybatis-plus:mapper-locations: classpath*:/mapper/**/*.xmlglobal-config:db-config:id-type: auto

关于配置mapper-locations: classpath*:/mapper/**/*.xml的说明:

  • 这个配置声明的是mybatis映射文件的路径
  • classpath中的号表示除了扫描当前项目的类路径,还会扫描所以来的包的类路径

下面的配置将主键设定为自增主键,在调用接口保存数据时,主键如果不指定,会自增。

global-config:db-config:id-type: auto

二,单元测试

1,编写测试代码,执行单元测试

在test文件夹下的测试类中,加入如下测试代码:

	@Autowiredprivate BrandService brandService;@Testpublic void testSaveBrand() {BrandEntity brandEntity = new BrandEntity();brandEntity.setName("华为");brandService.save(brandEntity);}

在这里插入图片描述
测运行testSaveBrand方法,测试通过说明配置正确。

在这里插入图片描述

数据库中也能看到一条对应的数据,说明单元测试成功,符合预期。

在这里插入图片描述

三,错误记录

1,单元测试失败初步排查

单元测试没跑成功,报错信息如下:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'attrAttrgroupRelationController': Unsatisfied dependency expressed through field 'attrAttrgroupRelationService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'attrAttrgroupRelationService': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'attrAttrgroupRelationDao' defined in file [D:\ideaprojects\gulimall2024\gulimall-product\target\classes\com\atguigu\gulimall\product\dao\AttrAttrgroupRelationDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.RuntimeException: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader

看上面堆栈信息的最后面的信息, Factory method 'dataSource' threw exception,说明极有可能是数据库连接信息配置的有问题。

在这里插入图片描述

仔细检查配置文件,发现数据库url配置少了端口信息。

在这里插入图片描述

修改配置文件,重新执行单元测试,仍然失败。

2,缺失驱动类依赖

仔细看堆栈信息,发现有这样一行:Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Threa,没有驱动类,应该是少了MySQL Driver相关的依赖。

考虑到这个依赖是其他模块也需要的依赖,所以应该在common模块的pom.xml中声明依赖。

		<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope><version>5.1.38</version></dependency>

在这里插入图片描述

http://www.mmbaike.com/news/107437.html

相关文章:

  • 极速网站建设服务商网站排名软件利搜
  • 上海和城乡建设委员会网站宁波seo网络推广多少钱
  • 网站开发技术大学教材seochinazcom
  • 黄岩做网站百度优化推广
  • 男女做暖暖不要钱的试看网站seo是干啥的
  • 东莞做网站卓诚百度官方电话人工服务电话
  • 永久免费网站建立nba最新交易一览表
  • 北京市网站制作设计有哪些可以免费推广的平台
  • 私服充值网站怎么做的常熟网络推广
  • 安庆网站建设推荐秒搜科技seo网站有优化培训班吗
  • 网站建设代码标签大全谷歌自然排名优化
  • 制作简单的个人网站推广网站的公司
  • 怎么用IP做网站地址关键字优化用什么系统
  • 做推送的网站有哪些线上购买链接
  • 好的建站网站百度推广客户端登录
  • 做网站如何收费客户管理软件
  • 网站建设网络推广加盟百度搜索推广和信息流推广
  • 长春网站z制作足球排名最新排名世界
  • 网站开发 技术指标宁波seo网络推广主要作用
  • 网站空间独立控制面板专业模板建站
  • 开源建站系统cms社群营销成功案例
  • 淘宝代运营去哪里找南宁网站seo排名优化
  • 猎头用什么网站做单2022年最近一周新闻大事
  • 贵州做网站的公司百度快照推广排名
  • 微网站如何做推广深圳网络营销技巧
  • 阳谷做网站如何优化seo
  • 提供温州手机网站制作哪家便宜网页浏览器
  • 网站开发名片怎么做五合一网站建设
  • 高端定制网站设计公司网站收录提交入口大全
  • 中国菲律宾足球直播海南seo