万事须己运,他得非我贤。这篇文章主要讲述通用mapper相关的知识,希望能为你提供帮助。
< !--通用mapper依赖--> < !--< dependency> --> < !--< groupId> tk.mybatis< /groupId> --> < !--< artifactId> mapper-spring-boot-starter< /artifactId> --> < !--< version> 2.1.5< /version> --> < !--< /dependency> -->
实体user:
@Table(name="user") // 配置实体映射的表名 public class User implements Serializable { private static final long serialVersionUID = -37900582537861695L; @Id // 必须配置不配置,如果使用通过ID查询的时候会把所有字段当作条件进行查询 private Integer id; private String userName; private String address; public String getUserName() { return userName; }public void setUserName(String userName) { this.userName = userName; }public String getAddress() { return address; }public void setAddress(String address) { this.address = address; }public Integer getId() { return id; }public void setId(Integer id) { this.id = id; } }
mapper:
@Component @org.apache.ibatis.annotations.Mapper public interface UserMapper extends Mapper< User> {}
测试test:
public class MapperTest extends ApplicationTests { @Autowired private UserMapper userMapper; ///////////////////////// 查询 测试 ///////////////////// // 测试根据ID查询,必须在注解字段标记@Id @Test public void testSelectById() throws Exception { List< User> users = userMapper.selectAll(); convertToJson(users); }// 测试根据指定的列进行查询 @Test public void testSelectByColumns() throws Exception { // 创建查询条件对象 Example example = new Example(User.class); example.and().andEqualTo("userName","admin") .andEqualTo("address","广州"); /* Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("userName","牧*人") .andEqualTo("updateTime","2020-04-21 23:42:13.0"); */ User user = userMapper.selectOneByExample(example); convertToJson(user); }
public void convertToJson(Object obj) {
System.out.println("result===> "+ JSON.toJSONString(obj, true));
}
【通用mapper】
推荐阅读
- 使用appium在android7.0真机上测试程序时报错command failed shell “ps ‘uiautomator’”的解决方式
- 飞凌i.MX6Q开发板Android系统下可以实现APP签名啦!速来
- macOS(无法打开“XXXX”,因为Apple无法检查其是否包含恶意软件。的解决办法)
- Android 之ANR
- Android SQLite轻量级数据库(简单介绍)
- 梦想Android版CAD控件2020.05.25更新
- callapply和bind函数存在的区别
- Appium等待方式
- 什么是Android中NDK开发