MyBatis при преобразовании элемента # {} появляется избыточный '? - PullRequest
0 голосов
/ 29 мая 2020

Я использую MyBatis для выполнения запроса sql, вот файл сопоставления:

  <select id="getDepByIdVersion"  resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from dependencies where id = #{repo_id} AND version = #{version_id} </select>

при преобразовании "# {version_id}" произошли странные вещи ———— отображается избыточная одинарная кавычка вверх :

2020-05-29 20:24:00.483  INFO 10684 --- [io-18080-exec-2] c.z.n.controller.RepoInfoController      : repo_id:1123
2020-05-29 20:24:00.483  INFO 10684 --- [io-18080-exec-2] c.z.n.controller.RepoInfoController      : version_id:1.0.0
2020-05-29 20:24:00.508  INFO 10684 --- [io-18080-exec-2] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-05-29 20:24:00.663  INFO 10684 --- [io-18080-exec-2] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-05-29 20:24:00.663 DEBUG 10684 --- [io-18080-exec-2] c.z.n.d.D.getDepByIdVersion              : ==>  Preparing: select id, version, dep_name, constraint from dependencies where id = ? AND version = ? 
2020-05-29 20:24:00.695 DEBUG 10684 --- [io-18080-exec-2] c.z.n.d.D.getDepByIdVersion              : ==> Parameters: 1123(String), 1.0.0(String)
2020-05-29 20:24:00.806 ERROR 10684 --- [io-18080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error querying 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 'constraint

    from dependencies where id = '1123' AND version = '1.0.0'' at line 3
### The error may exist in file [J:\Programming\NpmGraph\target\classes\mapper\DependenciesMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select           id, version, dep_name, constraint         from dependencies where id = ? AND version = ?
### 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 'constraint

    from dependencies where id = '1123' AND version = '1.0.0'' at line 3
; 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 'constraint

    from dependencies where id = '1123' AND version = '1.0.0'' at line 3] with root cause

Вы можете видеть сверху, оригинал - 1.0.0, а после преобразования он становится «1.0.0». Кто-нибудь знает почему?

1 Ответ

0 голосов
/ 31 мая 2020

Думаю, может быть, это из-за ограничения столбца, я проверю.

...