添加MyBatis Framework和MySQL Driver依赖
<!--mybatis集成springboot依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<!--mysql连接数据库驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3360/whynode
spring.datasource.username=root
spring.datasource.password=123
如何使用Lombok
@Data //lombok插件
public class Student {
private Integer id;
private String name;
private String sex;
private Integer age;
}
@Mapper
public interface StudentDao {
@Select("select * from t_student where id=#{id}")
Student getById(Integer id);
}
@SpringBootTest
class Ch02SpringbootMybatisApplicationTests {
@Autowired
private StudentDao studentDao;
@Test
void contextLoads() {
Student student = studentDao.getById(2);
System.out.println(student);
}
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/m0_60117382/article/details/121547263
内容来源于网络,如有侵权,请联系作者删除!