累累的 2019-07-17 12:38 采纳率: 100%
浏览 656

mybatis SQL片段引用错误! 求大神解答!

在我查询所有用户信息的时候 sql语句报错:
报错信息:

### The error occurred while setting parameters
### SQL: SELECT           FROM user
### 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 'FROM user' 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 'FROM user' at line 3] with root 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 'FROM user' at line 3**

这个是sql语句:

<select id="queryAll" resultType="User">
    SELECT <include refid="column" /> FROM user
</select>

这个是sql片段:

<sql id="column">
   <trim suffixOverrides=",">
    <if test="_parameter !=null">
     user_id,
    </if>
    <if test="_parameter !=null">
     user_account,
    </if>
    <if test="_parameter !=null">
     password,
    </if>
    <if test="_parameter !=null">
     user_name,
    </if>
    <if test="_parameter !=null">
     year,
    </if>
    <if test="_parameter !=null">
     email,
    </if>
    <if test="_parameter !=null">
     note,
    </if>
   </trim>
</sql>
  • 写回答

2条回答 默认 最新

  • xwh1314 2019-07-17 13:04
    关注

    应该是取最后一列的时候多了一个逗号

     <if test="_parameter !=null">
         note,
        </if>
    

    改为

         <if test="_parameter !=null">
         note
        </if>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看