Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Example in MyBatis

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

MyBatis Example how to use, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.

To use the example class, import the jar package mybatis.mapper into your project.

Mapper interface includes the function of adding, deleting, checking and paging a single table.

Take a look at the example, we are in the implementation class:

Example example = new Example(SysMenu.class);

example.createCriteria().andEqualTo("status","0");//only get menu of available status

List menus = menuMapper.selectByExample(example);

where SysMenu is the entity class of the system menu.

Take a look at this menuMapper:

public interface MenuMapper extends Mapper {

/**

* Get menu list

* @param sysMenu

* @param pager

* @return

*/

List getList(@Param("menu") SysMenu sysMenu,

@Param("pager") Pager pager);

}

It inherits Mapper , and it has a method in it. But it's not what we gave above.

It can be seen that this selectByExample is provided by Mapper.

Steps:

First create an instance Example = new Example(SysMenu.class); Add query criteria: example.createCriteria().andEqualTo("status","0");//Get only available status menu Finally call selectByExample to query:

List menus = menuMapper.selectByExample(example);

Example function of mapper in mybatis:

example Example analysis

Mybatis reverse engineering will generate instances and examples corresponding to instances, examples are used to add conditions, equivalent to the part after where

xxxExample example = new xxxExample();

Criteria criteria = new Example().createCriteria();

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report