小白求助下这段sql语句哪里有问题

白白了白呀白 2018-03-18 01:16:56

<mapper namespace="com.jeesite.modules.gjp.dao.GjpLedgerDao">
<resultMap id="BaseResultMap" type="com.jeesite.modules.gjp.entity.GjpLedger" >
<id column="lid" property="lid" jdbcType="INTEGER" />
<result column="parent" property="parent" jdbcType="VARCHAR" />
<result column="money" property="money" jdbcType="DOUBLE" />
<result column="account" property="account" jdbcType="VARCHAR" />
<result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
<result column="ldesc" property="ldesc" jdbcType="VARCHAR" />
<result column="create_by" property="createBy" jdbcType="VARCHAR" />
<result column="update_by" property="updateBy" jdbcType="VARCHAR" />
<result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />

<association property="sid" javaType="com.jeesite.modules.gjp.entity.GjpSort">
<id column="sid" property="sid" />
<result column="sname" property="sname"/>
<result column="parent" property="parent"/>
<result column="sdesc" property="sdesc"/>
<result column="create_by" property="createBy"/>
<result column="create_date" property="createDate"/>
<result column="update_by" property="updateBy"/>
<result column="update_date" property="updateDate"/>
</association>
</resultMap>
<!-- 插入 -->
<insert id="insertGjpLedger" parameterType="com.jeesite.modules.gjp.entity.GjpLedger">
insert into
gjp_ledger
(
parent,
sid.sname,
money,
account,
create_date,
ldesc,
update_date
)
value (
<if test="parent != null and parent != ''">and parent = #{parent, jdbcType=VARCHAR}</if>
<if test="sid.sname != null and sid.sname != ''">and sid.sname = #{sid.sname, jdbcType=INTEGER}</if>
<if test="money != null and money != ''">and money = #{money, jdbcType=DOUBLE}</if>
<if test="account != null and account != ''">and account = #{account, jdbcType=VARCHAR}</if>
<if test="createDate != null">and create_date = #{createDate, jdbcType=TIMESTAMP}</if>
<if test="ldesc != null and ldesc != ''">and ldesc = #{ldesc, jdbcType=VARCHAR}</if>
<if test="updateDate != null">and update_date = #{updateDate, jdbcType=TIMESTAMP}</if>
)
</insert>
我需要插入数据 然后报错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 'and parent = '0'
and sid.sname = '1'
and money = 999.0
and accoun' at line 13
我这语法哪里有问题吗?求教
...全文
364 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
白白了白呀白 2018-03-19
  • 打赏
  • 举报
回复
谢谢楼上两位,改过来可以正常插入了 可是数据库为什么显示插入的记录是Null呢,我用system打印出了来有接受到页面的值,后台也有显示
==>  Preparing: insert into gjp_ledger ( parent, money, account, create_date, ldesc, update_date ) values ( parent = ?, money = ?, account = ?, create_date = ?, ldesc = ?, update_date = ? ) 
03-19 10:29:54.005 DEBUG [c.j.modules.gjp.dao.GjpLedgerDao.insertGjpLedger] - ==> Parameters: 0(String), 999.0(Double), 工商银行(String), 2015-05-05 00:00:00.0(Timestamp), 野炊(String), 2015-05-05 00:00:00.0(Timestamp)
03-19 10:29:54.007 DEBUG [c.j.modules.gjp.dao.GjpLedgerDao.insertGjpLedger] - <==    Updates: 1
另外请问下怎么针对楼层进行回复啊 ,我怎么不能给相应的楼层回复呢
心随念 2018-03-19
  • 打赏
  • 举报
回复
老哥,是这样的吧。insert into aaa values(id,name,pwd) 你那个 values(and id=XXX, and name=xx,and pwd=XXX)是怎么个意思?
不才陈某 2018-03-19
  • 打赏
  • 举报
回复
你用的是动态sql语句,你只需要使用where标记来包裹if语句即可,where语句会帮你自动的去处多余的and
心随念 2018-03-19
  • 打赏
  • 举报
回复
引用 3 楼 qq389203946 的回复:
谢谢楼上两位,改过来可以正常插入了 可是数据库为什么显示插入的记录是Null呢,我用system打印出了来有接受到页面的值,后台也有显示
==>  Preparing: insert into gjp_ledger ( parent, money, account, create_date, ldesc, update_date ) values ( parent = ?, money = ?, account = ?, create_date = ?, ldesc = ?, update_date = ? ) 
03-19 10:29:54.005 DEBUG [c.j.modules.gjp.dao.GjpLedgerDao.insertGjpLedger] - ==> Parameters: 0(String), 999.0(Double), 工商银行(String), 2015-05-05 00:00:00.0(Timestamp), 野炊(String), 2015-05-05 00:00:00.0(Timestamp)
03-19 10:29:54.007 DEBUG [c.j.modules.gjp.dao.GjpLedgerDao.insertGjpLedger] - <== Updates: 1

另外请问下怎么针对楼层进行回复啊 ,我怎么不能给相应的楼层回复呢

看你输出的日志,应该是插入了。至于为什么没有值,你在看看。

另外如果想对某个楼层回复可以使用引用功能,


此回复就是引用的效果。
m0_37848367 2018-03-18
  • 打赏
  • 举报
回复
insert 里面 and <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="parent != null and parent != ' ' " > #{parent,jdbcType=VARCHAR}, </if> <if test="sname != null" > #{parent,jdbcType=INTEGER}, </if> .... </trim>

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧