现象如下,两方面原因:
1.@Select注解里面sql或者mapper.xml的sql错误。
2.如果sql确认没错,还有一个原因是javabean里面使用了mysql的关键词,造成解析错误,解决方式,是javabean中添加注册
@TableField("`global`") private Boolean global;
@TableField("`status`") private Boolean status;
扩展:https://download.csdn.net/course/detail/37057https://download.csdn.net/course/detail/37057
https://download.csdn.net/course/detail/37510https://download.csdn.net/course/detail/37510
类似这种。
package com.qi.rbac.entity;
import java.util.Date;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
/**
* 菜单(SysResource)实体类
*
* @author Array老师
* @since 2022-06-12 21:28:56
*/
@TableName(value = "sys_resource")
public class SysResource implements Serializable {
private static final long serialVersionUID = 206296861120689444L;
/**
* 主键
*/
private Long id;
/**
* 名称
*/
private String label;
/**
* 该节点的所有父节点
*/
private String treePath;
/**
* 权限
*/
private String permission;
/**
* 父级菜单ID
*/
private Long parentId;
/**
* 路径
*/
private String path;
/**
* 组件
*/
private String component;
/**
* 排序
*/
private Integer sequence;
/**
* 菜单图标
*/
private String icon;
/**
* 样式
*/
private String style;
/**
* 类型(1=菜单;2=按钮)
*/
private Integer type;
/**
* 1=启用;0=禁用
*/
@TableField("`status`")
private Boolean status;
/**
* 内置菜单(0=否;1=是)
*/
private Boolean readonly;
/**
* 公共资源
True是无需分配所有人就可以访问的
*/
@TableField("`global`")
private Boolean global;
/**
* 0=隐藏;1=显示
*/
private Boolean display;
/**
* 描述
*/
private String description;
/**
* 创建人id
*/
private Long createdBy;
/**
* 创建人名称
*/
private String createdName;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人id
*/
private Long lastModifiedBy;
/**
* 更新人名称
*/
private String lastModifiedName;
/**
* 更新时间
*/
private Date lastModifiedTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getTreePath() {
return treePath;
}
public void setTreePath(String treePath) {
this.treePath = treePath;
}
public String getPermission() {
return permission;
}
public void setPermission(String permission) {
this.permission = permission;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getComponent() {
return component;
}
public void setComponent(String component) {
this.component = component;
}
public Integer getSequence() {
return sequence;
}
public void setSequence(Integer sequence) {
this.sequence = sequence;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Boolean getStatus() {
return status;
}
public void setStatus(Boolean status) {
this.status = status;
}
public Boolean getReadonly() {
return readonly;
}
public void setReadonly(Boolean readonly) {
this.readonly = readonly;
}
public Boolean getGlobal() {
return global;
}
public void setGlobal(Boolean global) {
this.global = global;
}
public Boolean getDisplay() {
return display;
}
public void setDisplay(Boolean display) {
this.display = display;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
public String getCreatedName() {
return createdName;
}
public void setCreatedName(String createdName) {
this.createdName = createdName;
}
public Date getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
public Long getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(Long lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public String getLastModifiedName() {
return lastModifiedName;
}
public void setLastModifiedName(String lastModifiedName) {
this.lastModifiedName = lastModifiedName;
}
public Date getLastModifiedTime() {
return lastModifiedTime;
}
public void setLastModifiedTime(Date lastModifiedTime) {
this.lastModifiedTime = lastModifiedTime;
}
}
错误完整如下:
2022-06-29 00:01:24.530 - [] - ERROR 16176 --- [XNIO-1 task-1] com.qi.common.boot.base.GlobalExceptionHandler : [Mybatis 系统异常]
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, Error SQL: SELECT id,label,tree_path,permission,parent_id,path,component,sequence,icon,style,type,status,readonly,global,display,description,created_by,created_name,created_time,last_modified_by,last_modified_name,last_modified_time FROM sys_resource
WHERE (parent_id = ? AND type = ?)
### Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, Error SQL: SELECT id,label,tree_path,permission,parent_id,path,component,sequence,icon,style,type,status,readonly,global,display,description,created_by,created_name,created_time,last_modified_by,last_modified_name,last_modified_time FROM sys_resource
WHERE (parent_id = ? AND type = ?)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
at com.sun.proxy.$Proxy183.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
at com.baomidou.mybatisplus.core