### The error may exist in com/blacol/ncd/mapper/BaseInfoMapper.java (best guess)
### The error may involve com.blacol.ncd.mapper.BaseInfoMapper.insert
### The error occurred while executing an update
### SQL: INSERT INTO PUBLIC.BASEINFO ( id, name, foreignName, gender, height, weight, country, age, nation, education, bmi, iq, eq, energy, worldView, createTime ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
### Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "BASEINFO" not found; SQL statement:
INSERT INTO PUBLIC.BASEINFO ( id,
name,
foreignName,
gender,
height,
weight,
country,
age,
nation,
education,
bmi,
iq,
eq,
energy,
worldView,
createTime ) VALUES ( ?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
? ) [42102-200]
create table BASEINFO
(
ID CHARACTER not null,
NAME CHARACTER,
FOREIGNNAME CHARACTER,
HEIGHT DOUBLE PRECISION,
WEIGHT DOUBLE PRECISION,
COUNTRY CHARACTER,
AGE INTEGER,
NATION CHARACTER,
EDUCATION CHARACTER,
BMI DOUBLE PRECISION,
IQ INTEGER,
EQ INTEGER,
ENERGY INTEGER,
WORLDVIEW CHARACTER,
CREATETIME DATE,
GENDER CHARACTER(1),
constraint BASEINFO_PK
primary key (ID)
);
spring.datasource.url=jdbc:h2:~/db/ncd.mv.db;DB_CLOSE_DELAY=-1 # 有无DB_CLOSE_DELAY配置都一样
spring.web.resources.static-locations=classpath:/static/
package com.blacol.ncd.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import java.sql.Date;
@TableName("PUBLIC.BASEINFO")
//改成BASEINFO、baseinfo、public.baseinfo、@TableName(schema="PUBLIC",value="BASEINFO")均无效
public class BaseInfo {
private String id;
private String name;
@TableField("foreignName")
private String foreignName;
private String gender;
private double height;
private double weight;
private String country;
private int age;
private String nation;
private String education;
private double bmi;
private int iq;
private int eq;
private int energy;
@TableField("worldView")
private String worldView;
@TableField("createTime")
private Date createTime;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getForeignName() {
return foreignName;
}
public void setForeignName(String foreignName) {
this.foreignName = foreignName;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getNation() {
return nation;
}
public void setNation(String nation) {
this.nation = nation;
}
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
public double getBmi() {
return bmi;
}
public void setBmi(double bmi) {
this.bmi = bmi;
}
public int getIq() {
return iq;
}
public void setIq(int iq) {
this.iq = iq;
}
public int getEq() {
return eq;
}
public void setEq(int eq) {
this.eq = eq;
}
public int getEnergy() {
return energy;
}
public void setEnergy(int energy) {
this.energy = energy;
}
public String getWorldView() {
return worldView;
}
public void setWorldView(String worldView) {
this.worldView = worldView;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
@Override
public String toString() {
return "BaseInfo{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", foreignName='" + foreignName + '\'' +
", gender='" + gender + '\'' +
", height=" + height +
", weight=" + weight +
", country='" + country + '\'' +
", age=" + age +
", nation='" + nation + '\'' +
", education='" + education + '\'' +
", bmi=" + bmi +
", iq=" + iq +
", eq=" + eq +
", energy=" + energy +
", worldView='" + worldView + '\'' +
", createTime=" + createTime +
'}';
}
}
通过Mybatis-plus插入,插入实体类BaseInfo的对象,为了更直观的展示数据使用JSON表示:
{
"age":26,
"bmi":23.62,
"country":"sd",
"createTime":1645504184362,
"education":"bbbb",
"energy":6,
"eq":6,
"foreignName":"sda",
"gender":"m",
"height":177,
"id":"cc067f728381496",
"iq":6,
"name":"adas",
"nation":"dd",
"weight":74,
"worldView":"ggg"
}
已解决:
主要是因为idea项目结构的问题。
SpringBoot项目打包后会生成 target文件夹, h2的数据库文件也打包了进去。这样程序运行时是访问target里的数据库。如果要访问项目中的数据库文件可以将配置中url的~改成.
Table "BASEINFO" not found;