mybatisplus+pgsql查询bug的解决
最近公司把底层数据库,改换成了pgsql,之前一直是用的Mysql。可是换了pgsql之后,现在发现跟mybatisplus集成上,居然出现了一些很奇怪的bug。
这是sys_user表,我要根据id查这两条数据,一个id为3,一个id为5
这是4条查询语句,前2条根据id为3的查,后两条根据id为5的查
以下是根据id为3来查,
数据正常查了处理,departmentId也不为空,为啥这里我要提到 departmentId这段,请接着看,
奇怪的事情发生了,当id为5的查询时,数据也查出来了,确实是数据库里的那两条数据,但是
departmentId居然为null,这就很离谱
这是实体:
package com.xmirror.entity.entity.system;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JSONFORMat;
import com.fasterxml.jackson.annotation.jsonInclude;
import com.xmirror.entity.base.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.beans.Transient;
import java.util.*;
@Data
@TableName("sys_user")
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class User extends BaseEntity implements UserDetails {
private String username;
private String passWord;
private String realName;
private String phone;
private String email;
private Integer status;
private Integer departmentId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date authStartTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date authEndTime;
private Integer loginFailCount;
@TableField(exist = false)
private Integer roleId;
@TableField(exist = false)
private String roleName;
private String remark;
@TableField(exist = false)
private List<Permission> authorities;
public User() {
}
public User(Integer id){
super.setId(id);
}
public User(List<Permission> authorities, User user) {
this.authorities = authorities;
super.setId(user.getId());
super.setModifyDate(user.getModifyDate());
super.setCreateDate(user.getCreateDate());
username = user.getUsername();
password = user.getPassword();
realName = user.getRealName();
phone = user.getPhone();
email = user.getEmail();
status = user.getStatus();
departmentId = user.getDepartmentId();
authStartTime = user.getAuthStartTime();
authEndTime = user.getAuthEndTime();
}
@Transient
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
List<SimpleGrantedAuthority> auth = new ArrayList<>();
// 根据Permission生成权限列表
Optional.ofNullable(authorities)
.ifPresent(p -> p.forEach(permission -> {
auth.add(new SimpleGrantedAuthority(permission.getExpression()));
}));
return auth;
}
@Transient
@Override
public boolean isAccountNonExpired() {
return true;
}
@Transient
@Override
public boolean isAccountNonLocked() {
return true;
}
@Transient
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Transient
@Override
public boolean isEnabled() {
return true;
}
}
这是表结构
我把sql打印出来,拿来数据库里执行,都是能正常查出来的,说明单独跟pgsql没有关系,估计就是pgsql跟mybatisplus集成上的问题。而且也只有这一个字段出不来,并且也不是每条数据的这个字段出不来。
真是百思不得其解,都后悔用这pgsql这玩意儿了,不知道有朋友遇到过这种奇怪问题没有
到此这篇关于mybatisplus+pgsql查询bug的解决的文章就介绍到这了,更多相关mybatisplus pgsql查询bug内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
相关文章