SharePoint.Net

『笔记』iBatisNet的SQL动作

1、Select方法
  与iBatis For Java一样,iBatisNet的Select方法仍然可以返回List这个非常好用的集合对象。不过在.Net环境中,List对象改了一个定义方法。请看如下代码:

        //得到天气列表
        static public IList getWeatherList()
        
{
            IList listWeather 
= Mapper.Instance().QueryForList("SelectAll",null);
            
return listWeather;
        }


        
//得到分类列表
        static public IList getCategoryList(int _userId)
        
{
            IList listCategory 
= Mapper.Instance().QueryForList("SelectByUserId", _userId);
            
return listCategory;
        }

2、Insert 和 Update 方法
  看了iBatisNet的Guide上面写的是sqlMap.Insert("InsertPerson", personu)。但是貌似sqlMap仅仅是iBatis For Java里面的一个关键字。我在.Net环境中始终提示错误。后来改写成如下形式就可以了。反正我们需要的仅仅是一个Instant,一个Mapping的实例而已。

        //组装Article对象写库
        private void postArticle()
        
{
            T_Article articleu 
= new T_Article();
            articleu.CategoryId 
= Convert.ToInt32(this.ddlCategory.SelectedValue);
            articleu.UserId 
= ClassLib.getUserId();
            articleu.WeatherId 
= Convert.ToInt32(this.ddlWeather.SelectedValue);
            articleu.Title 
= this.txtTitle.Text.Trim();
            articleu.Summary 
= this.txtSummary.Text.Trim();
            articleu.Content 
= this.cePostArticle.Text;
            articleu.CreateDate 
= this.txtTime.Text.Trim();
            articleu.Visible 
= Convert.ToInt32(this.ddlVisible.SelectedValue);
            articleu.Feedbackble 
= Convert.ToInt32(this.ddlFeedbackble.SelectedValue);
            articleu.VisitTimes 
= 0;
            Mapper.Instance().Insert(
"InsertArticle",articleu);
        }


Mapper.Instance().Insert("InsertArticle",articleu);

生成一个Mapping实例,然后调用iBatisMap的内置方法Insert("FunctionName", Object)就可以了,其中InsertArticle是我在XML文件中定义的一个插入方法。

posted on 2005-11-01 10:03  Viva  阅读(1101)  评论(0编辑  收藏  举报

导航