<dependency>
<groupId>com.baomidougroupId>
<artifactId>mybatis-plus-boot-starterartifactId>
<version>3.5.1version>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
dependency>
<dependency>
<groupId>org.mybatis.spring.bootgroupId>
<artifactId>mybatis-spring-boot-starterartifactId>
<version>2.1.4version>
dependency>
如图所示,mybatis-plus-boot-starter
已经引入了jdbc 所以无需在引入 jdbc的依赖
只需要 填写数据源配置即可 。
spring:
datasource:
url: jdbc:mysql://localhost:3306/kaoyan?serverTimezone=UTC
password: admin
username: root
driver-class-name: com.mysql.cj.jdbc.Driver
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
@TableName(value = "user") // 指定查询的表名为 user
public class UserPlus {
// 以下为 mybatis-plus测试
private Integer id;
private String name;
private Integer age;
private String email;
}
特别简洁
package com.hoan.demo03242.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hoan.demo03242.bean.UserPlus;
public interface UserPlusMapper extends BaseMapper<UserPlus> {
}
@SpringBootTest
class Demo03242ApplicationTests {
@Autowired
UserPlusMapper userPlusMapper;
@Test
void contextLoads() {
UserPlus user = userPlusMapper.selectById(1);
System.out.println(user.toString());
}
}