我想通过mybatis先测试一下能不能从数据库访问ProductCategory表,参数都固定好了,结果一直抛出空指针,mybatis用的不熟,最后的测试类一直抛出空指针
public interface ProductCategoryDao {
//List<ProductCategory> queryProductCategory(@Param("productId") long ProductId);
List<ProductCategory> queryProductCategory();
}
public interface ProductCategoryService {
List<ProductCategory> getProductCategoryList();
}
@Service
public class ProductCategoryServiceImpl implements ProductCategoryService {
@Autowired
private ProductCategoryDao productCategoryDao;
@Override
public List<ProductCategory> getProductCategoryList() {
List<ProductCategory> productCategories = productCategoryDao.queryProductCategory();
return productCategories;
}
}
<mapper namespace="com.imooc.o2o.dao.ShopCategoryDao">
<select id="queryProductCategory" resultType="com.imooc.o2o.entity.ProductCategory" >
select
pc.priority,
pc.product_category_name,
pc.shop_id
from
tb_product_category as pc,
where pc.shop_id=1
</select>
</mapper>
public class ProductCategoryDaoTest {
@Autowired
ProductCategoryService productCategoryService;
@Test
public void testQueryProductCategory() {
List<ProductCategory> productCategoryList = productCategoryService.getProductCategoryList();
System.out.println(productCategoryList);
}
}
SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需
了解课程