通过generator生成的sql,执行时报错,把sql copy出来到数据库手动执行,发现也报错
org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'desc, tokensource, loginsource, author, addtime, modtime,
type, app_code, p' at line 3
### The error may exist in file [/Users/xxxx/target/test-classes/mappers/account/EcomauthDOMapper.xml]
### The error may involve m.account.interfacetest.dao.EcomauthDOMapper.selectByPrimaryKey-Inline
### The error occurred while setting parameters
### SQL: select id, appkey, appsecret, desc, tokensource, loginsource, author, addtime, modtime, type, app_code, partner_code, bgsource, octo_appkey from ecomauth where id = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'desc, tokensource, loginsource, author, addtime, modtime,
type, app_code, p' at line 3
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'desc, tokensource, loginsource, author, addtime, modtime,
type, app_code, p' at line 3
仔细看了下,是由于数据库中使用了类似type、desc等关键字,加 `type`符号转义下即可
<sql id="Base_Column_List">
id, appkey, appsecret, desc, tokensource, loginsource, author, addtime, modtime,
type, app_code, partner_code, bgsource, octo_appkey
</sql>
改为
<sql id="Base_Column_List">
id, appkey, appsecret, `desc`, tokensource, loginsource, author, addtime, modtime,
`type`, app_code, partner_code, bgsource, octo_appkey
</sql>