个人主页: 叶落闲庭
我的专栏:
c语言
数据结构
javaEE
操作系统
石可破也,而不可夺坚;丹可磨也,而不可夺赤。
@SpringBootTes(classes = SpringboottestApplication.class)
class SpringboottestApplicationTests{}
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis
username: root
password: 123456
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC
@Mapper
public interface UserDao {
@Select("select * from tb_user where id=#{id}")
public User selectById(@Param("id") int id);
}
@SpringBootTest
class SpringbootMybatisApplicationTests {
@Autowired
private UserDao userDao;
@Test
void testGetById() {
User user = userDao.selectById(1);
System.out.println(user);
}
}
<dependency>
<groupId>com.alibabagroupId>
<artifactId>druidartifactId>
<version>1.1.16version>
dependency>
server:
port: 80
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC
username: root
password: 123456
//TODO 添加@Mapper
@Mapper
public interface UserDao {
@Select("select * from tb_user where id=#{id}")
public User selectById(@Param("id") int id);
}
@SpringBootTest
class UserServiceImplTest {
@Autowired
private UserService userService;
@Test
void selectById() {
User user = userService.selectById(2);
System.out.println(user);
}
}