mybatis-plus insert时报错 表名order

今天遇到一个问题就是insert的时候语法没问题 插入日志也没问题 但是就是插不进去(忙了一上午啊 我的时间啊 可恶)

报错如图:

SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3180131e] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1409112532 wrapping com.mysql.cj.jdbc.ConnectionImpl@43c3354] will not be managed by Spring
==>  Preparing: INSERT INTO order ( pk_id, order_price, product_id ) VALUES ( ?, ?, ? )
==> Parameters: 1(String), 50(Integer), 1501002853813071874(String)
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3180131e]

org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order  ( pk_id,
order_price,
product_id )  VALUES  ( '1',
50,
'15010028538130718' at line 1
### The error may exist in com/zhang/mapper/OrderMapper.java (best guess)
### The error may involve com.zhang.mapper.OrderMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO order  ( pk_id, order_price, product_id )  VALUES  ( ?, ?, ? )
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order  ( pk_id,
order_price,
product_id )  VALUES  ( '1',
50,
'15010028538130718' at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order  ( pk_id,
order_price,
product_id )  VALUES  ( '1',
50,
'15010028538130718' at line 1

然后关注点放在

Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to

左想想 右想想 

我把表名改了 order->pro_order他就没问题了 可恶啊(order为mysql的关键字 拼接sql语句会出现问题)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
根据提供的引用内容,MyBatis-Plus的实现流程如下: 1. 引入MyBatis-Plus依赖,可以通过Maven方式引入,例如: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.1</version> </dependency> ``` 2. 配置MyBatis-Plus,可以在application.yml或application.properties文件中添加如下配置: ```yaml mybatis-plus: # mapper文件位置 mapper-locations: classpath:/mapper/*.xml # 实体类包名 typeAliasesPackage: com.example.entity ``` 3. 创建实体类,可以使用Lombok注解简化代码,例如: ```java @Data @NoArgsConstructor @AllArgsConstructor public class User { private Long id; private String name; private Integer age; private String email; } ``` 4. 创建Mapper接口,可以继承MyBatis-Plus提供的BaseMapper接口,例如: ```java public interface UserMapper extends BaseMapper<User> { } ``` 5. 创建Mapper.xml文件,可以使用MyBatis-Plus提供的自动填充功能,例如: ```xml <mapper namespace="com.example.mapper.UserMapper"> <resultMap id="BaseResultMap" type="com.example.entity.User"> <id column="id" property="id" /> <result column="name" property="name" /> <result column="age" property="age" /> <result column="email" property="email" /> </resultMap> <sql id="Base_Column_List"> id, name, age, email </sql> <insert id="insert" parameterType="com.example.entity.User"> <selectKey keyProperty="id" resultType="java.lang.Long" order="BEFORE"> SELECT IFNULL(MAX(id), 0) + 1 FROM user </selectKey> INSERT INTO user (id, name, age, email) VALUES (#{id}, #{name}, #{age}, #{email}) </insert> <update id="updateById" parameterType="com.example.entity.User"> UPDATE user SET name = #{name}, age = #{age}, email = #{email} WHERE id = #{id} </update> <select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Long"> SELECT <include refid="Base_Column_List" /> FROM user WHERE id = #{id} </select> <delete id="deleteById" parameterType="java.lang.Long"> DELETE FROM user WHERE id = #{id} </delete> <select id="selectList" resultMap="BaseResultMap"> SELECT <include refid="Base_Column_List" /> FROM user </select> </mapper> ``` 6. 在Service中调用Mapper接口,例如: ```java @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Override public User getById(Long id) { return userMapper.selectById(id); } @Override public List<User> list() { return userMapper.selectList(null); } @Override public boolean save(User user) { return userMapper.insert(user) > 0; } @Override public boolean updateById(User user) { return userMapper.updateById(user) > 0; } @Override public boolean removeById(Long id) { return userMapper.deleteById(id) > 0; } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

新生代农民工-小王八

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值