对update方法使用注解,但是报错
@Update("update tb_brand set brand_name brandName,company_name companyName,ordered ordered,description description,status status where id=#{id}")
void update(@Param("brand")Brand brand , @Param("id")Integer id);
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error updating 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 'brandName,company_name companyName,ordered ordered,description description,statu' at line 1
### The error may exist in com/itheima/mapper/BrandMapper.java (best guess)
### The error may involve com.itheima.mapper.BrandMapper.update-Inline
### The error occurred while setting parameters
### SQL: update tb_brand set brand_name brandName,company_name companyName,ordered ordered,description description,status status 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 'brandName,company_name companyName,ordered ordered,description description,statu' at line 1
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:67)
at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
at com.sun.proxy.$Proxy33.update(Unknown Source)
at com.itheima.service.impl.BrandServiceImple.update(BrandServiceImple.java:38)
at com.itheima.web.servlet.BrandServlet.update(BrandServlet.java:52)
... 25 more
Caused by: 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 'brandName,company_name companyName,ordered ordered,description description,statu' at line 1
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1199)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
... 31 more
麻烦采纳一下,你的采纳,是对我最好的鼓励,谢谢!
你好,sql语句写错了。
update tb_brand set brand_name= brandName这种形式
update tb_brand set brand_name brandName,company_name companyName,ordered ordered,description description,status status where id=#{id}
@Update("update tb_brand set brand_name brandName,company_name companyName,ordered ordered,description description,status status where id=#{id}")
void update(@Param("brand")Brand brand , @Param("id")Integer id);
update语句 写了更新的字段 但没有给字段赋值啊 改为下面样式
建议学习下MyBatis各注解使用方法
@Update("update tb_brand set brand_name = #{brandName},company_name = #{companyName} ,ordered = #{ordered},description =#{description} ,status = #{status} where id=#{id}")
void update(@Param("brandName")String brandName, @Param("companyName")String companyName , 补充........@Param("id")Integer id);
//也可以直接传整个对象 包含所有需要参数 id通过代码塞到对象里 这样就不需要@Param 多个参数的注解了
void update(Brand brand)