上一页 1 2 3 4 5 6 7 8 9 10 ··· 17 下一页
摘要: 第二种方法,采用结果查询:但老师的ID 要和学生的TID有个对应关系 注意事宜:SQL语句需加上 t.id tid 如果不注明 查出来的老师ID 则为O <select id="getStudent2" resultMap="StudentTeacher2"> select s.id sid,s.n 阅读全文
posted @ 2023-03-13 07:09 Rui2022 阅读(40) 评论(0) 推荐(0) 编辑
摘要: 在StudentMapper.xml 需要使用复杂查询的方法, 1、先单独查学生和单独查老师 2、在中间使用结果映射 学生中reultMap ="StudentTeacher" 3、中间增加结果映射 resultMap id ="StudentTeacher" type="Student" 还是学生 阅读全文
posted @ 2023-03-12 21:47 Rui2022 阅读(78) 评论(0) 推荐(0) 编辑
摘要: 搭建环境 新建数据库表格,teacher 和student 两张表格 在SQLyog中 CREATE TABLE `teacher` ( `id` INT(10) NOT NULL, `name` VARCHAR(30) DEFAULT NULL, PRIMARY KEY (`id`)) ENGIN 阅读全文
posted @ 2023-03-12 21:06 Rui2022 阅读(9) 评论(0) 推荐(0) 编辑
摘要: 第一步:Settings中加入plugins lombok 第二步:maven中导入依赖 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.24</versi 阅读全文
posted @ 2023-03-12 20:13 Rui2022 阅读(11) 评论(0) 推荐(0) 编辑
摘要: id 就是对应的namespace中的方法名; resultType 就是sql语句执行的返回值 (Class or 数据类型) parameterType 参数的类型 (方法名中的参数),如果为简单的数据类型,默认可以不写。 <select id="getUserById" parameterTy 阅读全文
posted @ 2023-03-12 19:49 Rui2022 阅读(11) 评论(0) 推荐(0) 编辑
摘要: 第一步:pojo的属性和数据库的列名不一样 package com.feijian.pojo; public class User { private int id; private String name; private String password; public User() { } pu 阅读全文
posted @ 2023-03-12 19:38 Rui2022 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 属性文件: resources - > db.properties driver=com.mysql.cj.jdbc.Driver url=jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncodin 阅读全文
posted @ 2023-03-10 16:18 Rui2022 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 接口类 //模糊查询 List <User> getUserLike(String value); 第二步:UserMapper.xml <!--模糊查询--> <select id="getUserLike" resultType="com.feijian.pojo.User"> select * 阅读全文
posted @ 2023-03-10 15:25 Rui2022 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 如果实体类或数据库中太多参数,我们应该考虑用MAP int addUser2(Map<String, Object> map); Mapper.xml <insert id="addUser2" parameterType="map" > insert into mybatis.user(id,na 阅读全文
posted @ 2023-03-10 15:03 Rui2022 阅读(7) 评论(0) 推荐(0) 编辑
摘要: 查,增,改,删 第一步:接口写入新方法 package com.feijian.dao; import com.feijian.pojo.User; import java.util.List; public interface UserMapper { //1.查询全部用户 List <User> 阅读全文
posted @ 2023-03-10 14:27 Rui2022 阅读(9) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 17 下一页