shaobaitou 2010-08-13 14:30
浏览 215
已采纳

Ibatis,main函数测试.取得到数据,却显示为Null

 今天刚刚接触Ibatis,写了一个超级简单的实例.却出错了,很悲哀。。。具体看我写的代码

       配置文件:
       <sqlMap>
       <typeAlias type="com.air.Products"  alias="prod"  />
      <!-- 获得一个用户 -->
<select id="getOnePro" parameterClass="string"  resultClass="prod">
     select * from product where pro_id=#proID#
</select>

<!--获得全部用户 -->
<select id="getAllPro" resultClass="prod"  >
     select * from product order by pro_number
</select>
     </sqlMap>



      Dao层:

         @SuppressWarnings("unchecked")
    public List<Products> getAllPro(){
    List<Products> list=new ArrayList<Products>();
    try {

        list= (List<Products>)this.queryForList("getAllPro");
        //return list;
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return list;
     }

       main函数:

public class Test {

/**
 * @param args
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    String resource="./SqlMapConfig.xml";
    Reader reader = null ;
    reader = Resources.getResourceAsReader(resource);
    SqlMapClientImpl smc=(SqlMapClientImpl)SqlMapClientBuilder.buildSqlMapClient(reader);


    ProductsService ps=new ProductsService(smc.delegate);

    List<Products> list=ps.getAllPro();
        System.out.println(list.size());
        Products pr=new Products();
        for (int i=0;i<20;i++){
             pr=list.get(i);
            System.out.println(pr.getProId()+" "+
                    pr.getProName()+" "+pr.getProPrice());  
        }

}

}

   显示:

212992
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0
0 null 0.0

  • 写回答

2条回答 默认 最新

  • iteye_4873 2010-08-16 09:11
    关注

    你的javaBean--com.air.Products这个的变量名称和表product字段名称一一对应吗,仔细检查下看看

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝