创建Maven项目后,一个个手动添加spring-boot和mybatis-plus依赖冲突问题 解决方案:找一个现成的pom.xml文件替换后重新加载(以下提供java8,对应的spring-boot,mybatis-plus依赖)
<?xml version="1.0" encoding="UTF-8"?>
< project xmlns = " http://maven.apache.org/POM/4.0.0" xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation= " http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion> 4.0.0</ modelVersion> < parent> < groupId> org.springframework.boot</ groupId> < artifactId> spring-boot-starter-parent</ artifactId> < version> 2.6.4</ version> < relativePath/> </ parent> < groupId> org.example</ groupId> < artifactId> MybatisPlusTest</ artifactId> < version> 1.0-SNAPSHOT</ version> < dependencies> < dependency> < groupId> org.springframework.boot</ groupId> < artifactId> spring-boot-starter</ artifactId> </ dependency> < dependency> < groupId> org.springframework.boot</ groupId> < artifactId> spring-boot-starter-test</ artifactId> </ dependency> < dependency> < groupId> com.baomidou</ groupId> < artifactId> mybatis-plus-boot-starter</ artifactId> < version> 3.4.0</ version> </ dependency> < dependency> < groupId> org.projectlombok</ groupId> < artifactId> lombok</ artifactId> </ dependency> < dependency> < groupId> mysql</ groupId> < artifactId> mysql-connector-java</ artifactId> </ dependency> < dependency> < groupId> org.springframework.boot</ groupId> < artifactId> spring-boot-starter-test</ artifactId> < version> RELEASE</ version> < scope> compile</ scope> </ dependency> </ dependencies> < properties> < maven.compiler.source> 8</ maven.compiler.source> < maven.compiler.target> 8</ maven.compiler.target> < project.build.sourceEncoding> UTF-8</ project.build.sourceEncoding> </ properties> </ project>
配置Mybatis-plus连接Mysql数据库,配置文件问题 解决方案:项目中没有,就在resources目录下新建一个application.yml文件(ssm修改成自己的数据库名,账号密码同理)
spring: datasource: url: jdbc: mysql: / / localhost: 3306 / ssm? serverTimezone= GMT % 2 B8 username: rootpassword: 123456 driver- class - name: com. mysql. cj. jdbc. Driver mybatis- plus: configuration: log- impl: org. apache. ibatis. logging. stdout. StdOutImpl logging: level: root: warncom. demo01. Mapper: tracepattern: console: "%p%m%n"
spring-boot启动类直接放在java目录下报错(原因https://blog.csdn.net/weixin_45931215/article/details/118609622) 一个新手容易忽略的小问题(实体类中的TableName注解要不要加) 解答: @TableName 不是必须的,但在以下场景下一定要使用,否则如下报错: 数据库表名与实体类名不一致。 表名不符合驼峰转下划线的规则。 涉及分库分表或动态表名的场景。 如果表名符合默认的映射规则,则可以省略。 注解不要忘记了!!!注解内容不要写错了!!! 不加会这样: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.mapper.UserMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}