1.自己写接口测试
第一步定义接口
@Mapper
public interface BookDao{
@Select("select * from tbl_book where id =#{id}")
Book getById(Integer id);
}
第二步 测试类
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class BookDaoTestCase {
@Autowired(required = false)//一般最好是写,不知道为什么不写会报错
private BookDao bookDao;
@Test
void TestGetById(){
System.out.println(bookDao.getById(1));
}
}
2.使用BaseMapper类
@Mapper
public interface BookDao extends BaseMapper<Book> {
// @Select("select * from tbl_book where id =#{id}")
// Book getById(Integer id);
}
直接使用BaseMapper提供的方法 都是以set开头的
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class BookDaoTestCase {
@Autowired(required = false)
private BookDao bookDao;
@Test
void TestGetById(){
System.out.println(bookDao.selectById(1));
}
}