8. The common generic interface methods Mapper

 1.select method 

@Test
     / ** 
     * value according to the attribute query, the query in a manner equal sign 
     * <P> the Title: testSelect </ P> 
     * <P> the Description: SELECT * WHERE ID = 110 from User </ P> 
     * @throws Exception
      * / 
    public  void testSelect () throws Exception {
         / * 
            query data id = 100 in 
            the user new new = U the user (); 
            u.setId (110); 
            ; userMapper.select (U) 
        * / 
        // All user table information 
        List <the User> List = userMapper.select ( null ); 
        System.out.println (List); 
    }

 

2. Press the primary key query

    @Test
    /**
     * 按表中主键查询数据
     * <p>Title: testselectByPrimaryKey</p>
     * <p>Description: </p>
     * @throws Exception
     */
    public void testSelectByPrimaryKey() throws Exception {
        User u = userMapper.selectByPrimaryKey(6);
        System.out.println(u);
    }

3. All of the data look-up table

    /**
     * 查询user表中所有数据
     * <p>Title: testSelectAll</p>
     * <p>Description: </p>
     * @throws Exception
     */
    @Test
    public void testSelectAll() throws Exception {
        List<User> list = userMapper.selectAll();
        System.out.println(list);
    }

4. Query single record

    /**
     * 根据条件查询单条数据
     * <p>Title: testSelectOne</p>
     * <p>Description: </p>
     * @throws Exception
     */
    @Test
    public void testSelectOne() throws Exception {
        User u=new User();
        u.setId(2);
        User user = userMapper.selectOne(u);
        System.out.println(user);
    }

5. Query the total number of records in accordance with the attribute value

    @Test
     / ** 
     * Total query data based on the attribute value 
     * <P> the Title: testSelectCount </ P> 
     * <P> the Description: </ P> 
     * @throws Exception
      * / 
    public  void testSelectCount () throws Exception { 
        the User U = new new the user (); 
        u.setFlag ( 1); // query normal user information 1 = 0 = normal soft-deleted 
        int COUNT = userMapper.selectCount (U); 
        System.out.println ( "total user:" + COUNT); 
    }

6. Save data

    @Test
     / ** 
     * save user 
     * <P> the Title: testInsert </ P> 
     * <P> the Description: </ P> 
     * / 
    public  void testInsert () 
    { 
        the User U = new new the User (); 
        u.setName ( " kkkkk " ); 
        u.setAge ( 30 ); 
        u.setFlag ( . 1 ); 
        userMapper.insert (U);   // INSERT () If the property is saved null null 
        System.out.println (U); 
        
        userMapper.insertSelective (U); // if the attribute is not stored null 
        
    }

modify

updateByPrimaryKey

updateByPrimaryKeySelective

 

delete

delete

deleteByPrimaryKey

Guess you like

Origin www.cnblogs.com/hua900822/p/11289929.html