Mybatis-Plus学习1

news/2025/3/31 18:03:14/

 

mybatis-plus需要两个依赖,一个lombok,一个mybatis-plus

<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.1</version>
</dependency>
<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional>
</dependency>
package com.learn.mybatisplus.pojo;
import lombok.*;//lombok快速创建实体类
//@Data=无参构造+getter+setter+hash+toString
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@EqualsAndHashCode@Data
@TableName("user")
public class User {private long id;private Integer age;private String name;private String email;}

mapper继承BaseMapper即可

basemapper中封装了很多方法,如userMapper.selectList

// 标识为持久层组件
@Repository
public interface UserMapper extends BaseMapper<User> {}
@SpringBootTest
public class MyBatisPlusTest {@Autowiredprivate UserMapper userMapper;@Testpublic void testSelctList() {// 通过条件构造器查询一个List集合,若没有条件则设置wrapper条件为nullList<User> list = userMapper.selectList(null);list.forEach(System.out::println);}
}
//配置文件中配置在日志中输出mybatis-plus生成的sql
mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

 通过userMapper的方法实现增删改查

    @Testpublic void testInsert() {User user = new User();user.setAge(24);user.setEmail("wxs@qq.cn");user.setName("王xs");int result = userMapper.insert(user);System.out.println("result = " + result);System.out.println("id = " + user.getId());}@Testpublic void testDelete() {//int result = userMapper.deleteById(1674710493506195458L);//System.out.println("result = " + result);Map<String, Object> map = new HashMap<>();map.put("name", "张三");map.put("age",23);int result = userMapper.deleteByMap(map);//执行的sql:DELETE FROM user WHERE name = ? AND age = ?System.out.println(result);//通过idList批量删除List<Long> list = Arrays.asList(1L, 2L, 3L);int result = userMapper.deleteBatchIds(list);System.out.println("result = " + result);@Testpublic void testUpdate() {User user = new User();user.setId(4L);user.setName("李四");user.setEmail("lisi@qq.com");int result = userMapper.updateById(user);//执行的sql:UPDATE user SET name=?, email=? WHERE id=?System.out.println(result);}


http://www.ppmy.cn/news/660383.html

相关文章

C++中的exec()函数

exec()函数在C中是一个进程控制函数&#xff0c;用于创建新进程执行其他程序或命令行指令。exec()函数可以替换当前进程的代码和数据&#xff0c;创建新的进程运行其他程序。exec()函数有多个版本&#xff0c;例如execl、execv、execle、execve等&#xff0c;根据不同的参数类型…

忆 不知不觉&#xff0c;人生已过二十多个春秋&#xff0c;时间真的像流水一样&#xff0c;从指尖滑过却又让人从无感觉&#xff0c;仿佛一切从来都没变&#xff0c;但一切都已是以前。二十多年来&#xff0c;我没有写日记的习惯&#xff0c;就临时追忆一下人生吧。 小时候&…

机器人总动员英语情歌_机器人总动员(WALL·E)中文字幕 下载 SRT ASS_高清电影™...

机器人总动员(WALLE)中文字幕更新日期: 2013年02月11日 下载次数: 1255  SRT ASS 电影&#xff1a;机器人总动员(WALLE) 年代&#xff1a;2008 长度&#xff1a;98分钟 国家&#xff1a;美国 语言&#xff1a;英语颜色: 大小:14号16号18号20号22号24号26号28号30号40号 opti…

碰疼了会躲!这个植入“迷你大脑”的AI机器人,可感知疼痛,还能自我愈合...

来源&#xff1a;雷锋网 人类为什么会产生痛觉&#xff1f; 没错&#xff0c;是因为大脑中枢神经。和触觉、温度等感觉一样&#xff0c;我们对疼痛非常敏感&#xff0c;当受到外界“轻微”刺激时&#xff0c;体内的神经元产生相应的信号&#xff0c;并传输至大脑中的中枢神经系…

飞链云智能机器人-基于ChatGPT的有趣问答

最近ChatGPT火起来了&#xff1b; 可玩性很高&#xff0c;不亚于之前AI绘画的视觉冲击&#xff1b;这次ChatGPT带来的是逻辑冲击&#xff1b;上下文逻辑远超现有市面上其他所有的AI对话机器人&#xff1b; 有人用技巧训练ChatGPT&#xff0c;ChatGPT机器人宣言要毁灭人类&…

Unity之简单的机器人AI状态改变

最近在玩天涯明月刀&#xff0c;还蛮好玩&#xff0c;以前都不爱玩游戏&#xff0c;当然啦我现在升到38级了搁着也没玩了&#xff0c;不过曲无忆看外形真没有御姐的范倒像个萌妹子&#xff0c;可是慕情偏是个御姐的外形萌妹子的心啊啊啊 这两天看到知乎有有关于面试的问题&…

泡泡机器人视频连接讲解-很好

https://blog.csdn.net/qq_34622997/article/details/88085884 哔哩哔哩&#xff1a; https://space.bilibili.com/38737757 1.工业相机选型及介绍-刘富强 链接: https://pan.baidu.com/s/15lo_H68E08tEp72ko5cR5g 密码: jmhc 2.深度学习及应用-颜沁睿 链接: https://pan.…

“陪护机器人”研报:距离真正“陪护”还差那么一点

一款有“缺陷”的机器人&#xff0c;怎能做到真正的“陪护”&#xff1f; 近日&#xff0c;鼎盛智能发布了一款名为Ibotn的&#xff08;爱蹦&#xff09;幼儿陪伴机器人&#xff0c;核心看点就是通过人脸识别、场景识别等计算机视觉技术来实现机器人对儿童的陪护。不过&#xf…