java.lang.NoClassDefFoundError

java.lang.NoClassDefFoundError

昨天都还好好的,今天不知道为什么就提示找不到工具类了

mappers/goods.xml

<resultMap id="rmGoods" type="com.imooc.mybatis.dto.GoodsDTO">
    <!-- 设置主键字段与属性映射-->
    <id property="goods.goodsId" column="goods_id"></id>
    <!--设置非主键字段与属性映射-->
    <result property="goods.title" column="title"></result>
    <result property="goods.originaCost" column="original_cost"></result>
    <result property="goods.currentPrice" column="current_price"></result>
    <result property="goods.discount" column="discount"></result>
    <result property="goods.isFreeDelivery" column="is_free_delivery"></result>
    <result property="goods.categoryId" column="category_id"></result>
    <result property="category_name" column="category_name"/>
    <result property="test" column="test"/>
</resultMap>
<select id="selectGoodsDTO" resultMap="rmGoods">
    SELECT g.* ,c.category_name,"1" AS test FROM t_goods g,t_category c
    WHERE g.category_id = c.category_id
</select>

com.imooc.mybais.dto/GoodsDTO

@Test
public void testSelectGoodsDTO() throws Exception {
    SqlSession session = null ;
    try{
        session = MyBatisUtils.openSession();
        List<GoodsDTO> list = session.selectList("goods.selectGoodsDTO");
        for(GoodsDTO g:list){
            System.out.println(g.getGoods().getTitle());
        }
    }catch (Exception e){
        throw e;
    }finally {
        MyBatisUtils.closeSession(session);
    }
}

这是错误提示

java.lang.NoClassDefFoundError: Could not initialize class com.imooc.mybatis.utils.MyBatisUtils

at com.imooc.mybatis.MyBatisTestor.testSelectGoodsDTO(MyBatisTestor.java:155)


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

1、建议同学重新编译一下,如果是eclipse,则选择:

http://img1.sycdn.imooc.com//climg/5db404d00958d40c02280225.jpg

2、如果是idea:

http://img1.sycdn.imooc.com//climg/5db404ed09a5b33403220226.jpg

或删除target文件。

3、如果还是不行,请同学贴一下你的项目目录结构截图和完整的报错信息。

4、另外,MyBatisTestor.java:155  MyBatisTestor中的第155行代码是具体哪行呢?

注意不要贴在回复里,会失去代码的格式。可以在回答里贴一下。祝学习愉快。

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师