<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc8</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- mybatis-plus--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>2.3</version> </dependency> <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>2.3</version> </dependency> <!-- mybatis--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.6</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.4</version> </dependency> <!-- lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.20</version> </dependency> <!--oracle字符集 https://mvnrepository.com/artifact/cn.easyproject/orai18n--> <dependency> <groupId>cn.easyproject</groupId> <artifactId>orai18n</artifactId> <version>12.1.0.2.0</version> </dependency> </dependencies>
spring.datasource.username=root spring.datasource.password=root spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
@Mapper @Repository public interface UserMapper extends BaseMapper<User> { }
@AllArgsConstructor @NoArgsConstructor @TableName("tb_user") @Data public class User implements Serializable { private Integer user_id; private String user_name; private String user_pwd; }
添加@MapperScan注解,扫描包,放在@SpringBootApplication注解上面
@SpringBootTest class MybatisPlusApplicationTests { @Autowired UserMapper userMapper; @Test void contextLoads() { List<User> users = userMapper.selectList(null); for (User user : users) { System.out.println(user); } } }