List<GoodsDTO> list = session.selectList("goods.selectGoodsDTO");有一行报错
相关截图:
相关代码:
package com.imooc.mybatis; import com.imooc.mybatis.dto.GoodsDTO; import com.imooc.mybatis.entity.Goods; import com.imooc.mybatis.utils.MyBatisUtils; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Test; import java.io.IOException; import java.io.Reader; import java.sql.Connection; import java.util.HashMap; import java.util.List; import java.util.Map; public class MybatisTestor { @Test public void testSqlSessionFactory() throws IOException { Reader reader=Resources.getResourceAsReader("mybatis-config.xml"); SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(reader); System.out.println("SessionFactory加载成功"); SqlSession sqlSession=null; try { sqlSession=sqlSessionFactory.openSession(); Connection connection=sqlSession.getConnection(); System.out.println(connection); }catch (Exception e){ e.printStackTrace(); }finally { if (sqlSession!=null){ sqlSession.close(); } } } @Test public void testMyBatisUtils(){ SqlSession sqlSession =null; try { sqlSession= MyBatisUtils.openSession(); Connection connection = sqlSession.getConnection(); System.out.println(connection); }catch (Exception e){ throw e; }finally { MyBatisUtils.closeSession(sqlSession); } } @Test public void testSelectAll(){ SqlSession session=null; try { session= MyBatisUtils.openSession(); List<Goods> list=session.selectList("goods.selectAll"); for (Goods g:list){ System.out.println(g.getTitle()); } }catch (Exception e){ throw e; }finally { MyBatisUtils.closeSession(session); } } @Test public void testSelectById() throws Exception{ SqlSession session=null; try { session= MyBatisUtils.openSession(); Goods goods=session.selectOne("goods.selectById" , 1602); System.out.println(goods.getTitle()); }catch (Exception e){ throw e; }finally { MyBatisUtils.closeSession(session); } } @Test public void testSelectByPriceRange() throws Exception{ SqlSession session=null; Map param=new HashMap<>(); param.put("min",100); param.put("max",500); param.put("limt",10); try { session= MyBatisUtils.openSession(); List<Goods> list=session.selectList("selectByPriceRange",param); for (Goods g:list) { System.out.println(g.getTitle()+":"+g.getCurrentPrice()); } }catch (Exception e){ throw e; }finally { MyBatisUtils.closeSession(session); } } @Test public void testSelectGoodsMap() throws Exception{ SqlSession session=null; try { session= MyBatisUtils.openSession(); List<Map> list=session.selectList("goods.selectGoodsMap"); for (Map map:list){ System.out.println(map); } }catch (Exception e){ throw e; }finally { MyBatisUtils.closeSession(session); } } @Test public void testSelectGoodsDTO(){ 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); } } }
5
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星