笔者的使用mysql数据库,实体如下

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.type.JdbcType;import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "api_ocr_document")
public class ApiOCRDocument{

    @Id
    @GeneratedValue(generator = "JDBC")
    private Long id;

    private String mimeType;

    private String hash;

    private byte[] binary;

    private String text;

    private String createTime;
}

插入语句生成的sql如下

INSERT INTO api_ocr_document  ( id,mime_type,hash,binary,text,create_time ) VALUES( ?,?,?,?,?,? )

放到navicat一看,两个关键字(hash,binary)

 

 

 解决方法,使用tk.mybatis私有注解ColumnType将字段使用mysql关键字·转义一下

正确代码如下:

package com.netmarch.web.open.bean;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.type.JdbcType;
import tk.mybatis.mapper.annotation.ColumnType;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "api_ocr_document")
public class ApiOCRDocument{

    @Id
    @GeneratedValue(generator = "JDBC")
    private Long id;

    private String mimeType;

    @ColumnType(column = "`hash`",jdbcType = JdbcType.VARCHAR)
    private String hash;

    @ColumnType(column = "`binary`",jdbcType = JdbcType.BLOB)
    private byte[] binary;

    private String text;

    private String createTime;
}

再次生成的sql如下

 

posted on 2020-01-02 09:08  你不知道的浪漫  阅读(4820)  评论(0编辑  收藏  举报