zoukankan      html  css  js  c++  java
  • mybatis和mybatisPlus中解决实体类字段与数据库关键字冲突问题

    可能你插入字段为关键字时报如下错误,且字段名不适合改变

    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

    一.mybatis中

    方案一:如果是在xml文件中,插入语句时可以加上` `,例如

    <!--批量新增-->
        <insert id="addBatch"  useGeneratedKeys="true" keyProperty="id"  parameterType="com.pct.dotware.pams.entity.EmpStsDetail">
            insert into emp_sts_detail
            (
                `emp_name`,
                `emp_id`,
                `item_id`,
                `item_name`,
                `price_id`,
                `emp_sts`,
                `cus_id`,
                `cus_name`,
                `cus_rank`,
                `start_date`,
                `end_date`,
                `update_date`,
                `remark`
            )
            values
            <foreach item="item" collection="list" open="(" separator="),(" close=")">
                #{item.empName},
                #{item.empId},
                #{item.itemId},
                #{item.itemName},
                #{item.priceId},
                #{item.empSts},
                #{item.cusId},
                #{item.cusName},
                #{item.cusRank},
                #{item.startDate},
                #{item.endDate},
                #{item.updateDate},
                #{item.remark}
            </foreach>
        </insert>

    方案二:在实体类中加入注解

    @Column(name = "`left`")
    private Double left;

    二.mybatisPlus中

    方案一.加@TableField注解,给上别名加上反单引号,比如

    @TableField("`month`")
    private String month;
  • 相关阅读:
    (22)进程和线程区别
    (21)回调函数
    (20)gevent协程
    (18)ProcessPoolExecutor进程池
    (19)ThreadPoolExecutor线程池
    (17)线程队列---queue LifoQueue PriorityQueue
    (16)线程---定时器Timer
    (15)线程---Condition条件
    (14)线程- Event事件和守护线程Daemon
    IDEA快速搭建WEB项目【记录篇】
  • 原文地址:https://www.cnblogs.com/zhukf/p/12975066.html
Copyright © 2011-2022 走看看