![]() |
1
waterlaw 2024-04-15 00:32:48 +08:00 via Android
mybatis 什么版本不说一下 😂
|
![]() |
2
NiceGeekJasonChu OP @waterlaw <dependency>
<groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.13</version> </dependency> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>4.1.5</version> </dependency> |
![]() |
3
NiceGeekJasonChu OP SQL 日志打印出来居然不是根据主键 id 更新:
Preparing: UPDATE admin SET name = ?,password = ?,age = ?,sex = ?,phone = ? WHERE name = ? AND password = ? AND age = ? AND sex = ? AND phone = ? |
![]() |
4
waterlaw 2024-04-15 00:56:09 +08:00
@NiceGeekJasonChu 实体类和 Mapper 看下,tkmybatis 没用过
|
![]() |
5
NiceGeekJasonChu OP |
![]() |
6
waterlaw 2024-04-15 01:01:22 +08:00
@NiceGeekJasonChu Mapper 直接使用这个实体类 Admin 吗?还需要配置 Admin 的扫描路径吗
|
![]() |
7
waterlaw 2024-04-15 01:09:33 +08:00
我这边更新成功了 ,id 列加下注解 @Column
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "id") private Integer id; |
![]() |
8
waterlaw 2024-04-15 01:11:27 +08:00
不加 @Column 注解也是更新成功的,mybatis-spring-boot-starter 和 mapper 的版本和你一样
|
![]() |
9
waterlaw 2024-04-15 01:14:30 +08:00
create table admin(id int(32) primary key, name varchar(20)); 必须声明主键,否则更新失败。
|
![]() |
10
waterlaw 2024-04-15 01:50:33 +08:00
不是主键也更新成功了。create table admin(id int(32), name varchar(20));
|
![]() |
11
RedBeanIce 2024-04-15 06:33:02 +08:00 via iPhone
你的注解不是 mybatis 的。
|
![]() |
12
RedBeanIce 2024-04-15 08:05:51 +08:00
@RedBeanIce 我错了,,请使用 mybatisplus 吧,tk mapper 不行了。
|
![]() |
13
NiceGeekJasonChu OP |
![]() |
14
forest997 2024-04-15 10:24:29 +08:00
是不是 @Id 用成了别的包的,正确的是 javax.persistence 包的,mapper.xml 的 resultMap 里面有没有配<id>
|
![]() |
17
pangdundun996 2024-04-15 10:29:42 +08:00
debug 看看 sql 生成逻辑,这种估计是内部注解处理的问题
|
![]() |
18
NiceGeekJasonChu OP @forest997 这个我检查过了,是 javax. persistence
|
![]() |
19
NiceGeekJasonChu OP @pangdundun996 debug 过了,日志也打了,where 条件里面压根就没有 id ,打印日志我上面发过
|
![]() |
20
NiceGeekJasonChu OP 问题找到了,我在主键上加上 @Column(name = "id")注解,就能更新成功。但是我看有的人没有加这个注解,也能更新成功。
|
![]() |
21
xuanbg 2024-04-16 04:23:01 +08:00
你这是表没有主键吧
|
![]() |
22
pangdundun996 2024-04-16 09:50:23 +08:00
@NiceGeekJasonChu 我意思是你看看生成 sql 的逻辑,看框架是怎么处理注解的
|
![]() |
23
NiceGeekJasonChu OP |