1、错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [/system] 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 '"test"' at line 1 ### The error may exist in file [D:dev_projectcoursesystem argetclassesmapperTestMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT id,name FROM "test"
原因是sql语句有语法问题。
select “id”,“name” from "user" 其中id和name是user表的字段,问题在三个都不能加双引号,user表名加双引号后报上述错误,而字段名加双引号会被识别为字符串,从而在表中找到相应的字符串而不是字段对应的内容。
故正确写法如下:
select id,name from user