发表于: 2017-08-02 22:29:36

1 1012


今天完成的:

学习dal

收获:学习了mybatis generator

------------------------------

//自定义条件查询

   @Test

   public void testSelectByExample() {

      ItemsExampleitemsExample = newItemsExample();

      //通过criteria构造查询条件

      ItemsExample.Criteriacriteria = itemsExample.createCriteria();

      criteria.andNameEqualTo("笔记本3");

      //可能返回多条记录

      List<Items>list = itemsMapper.selectByExample(itemsExample);

     

      System.out.println(list);

     

   }

 

   //根据主键查询

   @Test

   public voidtestSelectByPrimaryKey() {

      Itemsitems = itemsMapper.selectByPrimaryKey(1);

      System.out.println(items);

   }

 

 

//插入

   @Test

   public void testInsert() {

      //构造 items对象

      Itemsitems = newItems();

      items.setName("手机");

      items.setPrice(999f);

      itemsMapper.insert(items);

   }

 

//更新数据

   @Test

    public void testUpdateByPrimaryKey() {

       //对所有字段进行更新,需要先查询出来再更新

       Items items = itemsMapper.selectByPrimaryKey(1);

       items.setName("水杯");

       itemsMapper.updateByPrimaryKey(items);

       //如果传入字段不空为才更新,在批量更新中使用此方法,不需要先查询再更新

       //itemsMapper.updateByPrimaryKeySelective(record);

    }

---------------------

遇到的问题:

暂无

明天的计划:

设计方案,做复盘项目


返回列表 返回列表
评论

    分享到