Spring-mybatis-入门程序

This commit is contained in:
2025-09-25 11:12:22 +08:00
parent 7228061094
commit c49a7571f6
7 changed files with 270 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package com.inmind;
import com.inmind.mapper.UserMapper;
import com.inmind.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {
@Autowired//直接从IOC容器中获取UserMapper类型的对象
private UserMapper userMapper;
@Test
void contextLoads() {
//使用mybatis框架查询所有用户的数据
List<User> list = userMapper.list();
list.stream().forEach(user -> {
System.out.println(user);
});
}
}