使用MybatisPlus自动插入相应的字段时应该注意
报错信息:
Error updating database. Cause: java.sql.SQLException: Field ‘sort_order’ doesn’t have a default value
The error may involve com.ultrapower.life.mapper.WxMainDetailMapper.insert-Inline
The error occurred while setting parameters
SQL: INSERT INTO wx_main_detail ( home_id, image_url, status, create_time ) VALUES ( ?, ?, ?, ? )
Cause: java.sql.SQLException: Field ‘sort_order’ doesn’t have a default value
; Field ‘sort_order’ doesn’t have a default value; nested exception is java.sql.SQLException: Field ‘sort_order’ doesn’t have a default value
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:246)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate
S
q
l
S
e
s
s
i
o
n
I
n
t
e
r
c
e
p
t
o
r
.
i
n
v
o
k
e
(
S
q
l
S
e
s
s
i
o
n
T
e
m
p
l
a
t
e
.
j
a
v
a
:
446
)
a
t
c
o
m
.
s
u
n
.
p
r
o
x
y
.
SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) at com.sun.proxy.
SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)atcom.sun.proxy.Proxy101.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:64)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:61)
at com.sun.proxy.
P
r
o
x
y
113.
i
n
s
e
r
t
(
U
n
k
n
o
w
n
S
o
u
r
c
e
)
a
t
c
o
m
.
b
a
o
m
i
d
o
u
.
m
y
b
a
t
i
s
p
l
u
s
.
e
x
t
e
n
s
i
o
n
.
s
e
r
v
i
c
e
.
i
m
p
l
.
S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idou.mybatisplus.extension.service.impl.ServiceImpl.save(ServiceImpl.java:105) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:206) at com.sun.proxy.
Proxy113.insert(UnknownSource)atcom.baomidou.mybatisplus.extension.service.impl.ServiceImpl.save(ServiceImpl.java:105)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)atjava.lang.reflect.Method.invoke(Method.java:498)atorg.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)atorg.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:206)atcom.sun.proxy.Proxy115.save(Unknown Source)
问题根源:在插入的时候没有值,故报错!
解决办法:在MybatisPlus自动插入 的方法设置需要插入数据库的值;如下所示:
这是我需要插入的字段
把这个加上之后就可以了,