Mybatis逆向生成器的生成的代码使用详情:

一、生成后的全部方法:

1、countByExample(xxxExample example);  //按条件查询获得的数据条数

2、deleteByExample(xxxExample example); //按条件删除对应的数据

3、deleteByPromaryKey(Integer id); //按照主键删除数据

4、int insert(User record); //无论字段是否为null,都帮你插入

5、int insertSelective(User record); //只有不为null的字段才插入

6、List<User> selectByExample(xxxrExample example); //根据条件去查询数据(集合)

7、User selectByPrimaryKey(Integer id); //根据主键查询数据对象(单条)

8、int updateByExampleSelective(@Param("record") User record,@Param("example") UserExample example);

        //根据条件去更新值不为null的字段

9、int updateByExample(@Param("record") User record,@Param("example") UserExample example);

        //根据条件去更新全部字段

10、int updateByPrimaryKeySelective(User record);//根据主键更新值不为null的字段

11、int updateByPrimaryKey(User record);  //根据主键更新全部字段

二、xxxExamples实例的使用:

1、首先实例出来xxxExample  example = new xxxExample();

        1)此时如果需要排序order by或者distinct,可以在这里设置,设置如下:

                    example.setOrderByClause(“字段名  desc”)    //asc升序  desc降序

                    example.setDistinct(true);  //true代表过滤掉重复的数据

2、得到自己的方法Criteria criteria = example.createCriteria();

3、就可以加条件了,这里演示模糊查询的条件书写,其他都比较简单:

    1)criteria.andPwdLike("%"+value+"%");

好了,其他就不多说了,真实开发也就用到以上这些都能解决的了,除了一些多表联查的就自己重根据需求去写xml文件慢慢研究就好,都不难的。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容