Closed sgxiaoxu closed 2 years ago
支持,你的问题只是h2数据库版本问题。
解决方法:
@TableName("`user`")
@Data
public class User {
private Long id;
private String name;
private Integer age;
private String email;
}
schema-h2.sql
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user`
(
id BIGINT NOT NULL COMMENT '主键ID',
name VARCHAR(30) NULL DEFAULT NULL COMMENT '姓名',
age INT NULL DEFAULT NULL COMMENT '年龄',
email VARCHAR(50) NULL DEFAULT NULL COMMENT '邮箱',
PRIMARY KEY (id)
);
data-h2.sql
DELETE FROM `user`;
INSERT INTO `user` (id, name, age, email) VALUES
(1, 'Jone', 18, 'test1@baomidou.com'),
(2, 'Jack', 20, 'test2@baomidou.com'),
(3, 'Tom', 28, 'test3@baomidou.com'),
(4, 'Sandy', 21, 'test4@baomidou.com'),
(5, 'Billie', 24, 'test5@baomidou.com');
application.yml
spring:
datasource:
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
url: jdbc:p6spy:h2:mem:test
username: root
password: test
sql:
init:
schema-locations: classpath:db/schema-h2.sql
data-locations: classpath:db/data-h2.sql
encoding: UTF-8
支持,你的问题只是h2数据库版本问题。 你的h2用什么版本呢?
当前使用版本(必填,否则不予处理)
MP 3.5.2
该问题是如何引起的?(确定最新版也有问题再提!!!)
更改spring boot版本
重现步骤(如果有就写完整)
在学习mybatis-plus-samples-master这个项目的时候,我自己动手做了一个demo 使用的是dependencyManagement的方式做module
您可以尝试将下面附件里的父工程的pom.xml的2.6.11</org.springframework.boot.version>改成2.7.x的版本
然后运行
报错信息
org.springframework.jdbc.BadSqlGrammarException:
Error querying database. Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT id,name,age,email FROM [*]user"; expected "identifier"; SQL statement:
SELECT id,name,age,email FROM user [42001-214]
The error may exist in cn/com/kcwx/mapper/UserMapper.java (best guess)
The error may involve cn.com.kcwx.mapper.UserMapper.selectList
The error occurred while executing a query
SQL: SELECT id,name,age,email FROM user
Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT id,name,age,email FROM [*]user"; expected "identifier"; SQL statement:
SELECT id,name,age,email FROM user [42001-214] ; bad SQL grammar []; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT id,name,age,email FROM [*]user"; expected "identifier"; SQL statement: SELECT id,name,age,email FROM user [42001-214]
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT id,name,age,email FROM [*]user"; expected "identifier"; SQL statement: SELECT id,name,age,email FROM user [42001-214]
MyTestMybatisPlus.zip