1
gejun123456 2019-05-21 21:48:32 +08:00
sql 看看,可以试试 bind 标签
<bind name="hello" value="$"> select * from where id = #{hello} |
2
Belmode 2019-05-21 22:15:18 +08:00
html 符号实体 $
``` $ ``` |
3
zhady009 OP @gejun123456 就是用你插件生成的 insert 买了一年
|
4
zhady009 OP @gejun123456 就比如一个 username 字段 value 是 x$x
|
5
gejun123456 2019-05-21 22:56:43 +08:00
@zhady009 #4 我试了下没发现问题。
java 代码: User record = new User(); record.setUserName("x$x"); mapper.insertSelective(record); xml: <insert id="insertSelective" keyColumn="user_id" keyProperty="userId" parameterType="com.codehelper.domain.User" useGeneratedKeys="true"> <[email protected]> insert into user <trim prefix="(" suffix=")" suffixOverrides=","> <if test="userName != null"> user_name, </if> <if test="birth != null"> birth, </if> <if test="salary != null"> salary, </if> <if test="ssssssss != null"> ssssssss, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="userName != null"> #{userName}, </if> <if test="birth != null"> #{birth}, </if> <if test="salary != null"> #{salary}, </if> <if test="ssssssss != null"> #{ssssssss}, </if> </trim> 插入没问题,另外你这个是报啥错哈 |
6
zhady009 OP @gejun123456 mybtis 版本 3.4.6
java: AdPlanRtReport adPlanRtReport = new AdPlanRtReport(); adPlanRtReport.setUserId(0L); adPlanRtReport.setPlanId(0L); adPlanRtReport.setPlanName("212$"); adPlanRtReportMapper.insertSelective(adPlanRtReport); ...省略 xml: <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="xxx.AdPlanRtReport" useGeneratedKeys="true"> <[email protected]> insert into ad_plan_rt_report <trim prefix="(" suffix=")" suffixOverrides=","> <if test="userId != null"> user_id, </if> <if test="planId != null"> plan_id, </if> <if test="planName != null"> plan_name, </if> ...省略 </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="userId != null"> #{userId,jdbcType=BIGINT}, </if> <if test="planId != null"> #{planId,jdbcType=BIGINT}, </if> <if test="planName != null"> #{planName,jdbcType=VARCHAR}, </if> ...省略 </trim> </insert> 报错信息: Error updating database. Cause: java.lang.IllegalArgumentException: Illegal group reference ### The error may involve xxx.mapper.AdPlanRtReportMapper.insertSelective-Inline ### The error occurred while setting parameters ### SQL: insert into ad_plan_rt_report ( user_id, plan_id, plan_name, cpm, roi, impression, click, ctr, spend, cpc, order_num, gmv, scene_type, ad_unit_num, mall_fav_num, max_cost, account_status, `status`, operate_status, is_deleted, report_date, report_time ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ### Cause: java.lang.IllegalArgumentException: Illegal group reference at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) at com.sun.proxy.$Proxy35.insert(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) at com.sun.proxy.$Proxy58.insertSelective(Unknown Source) |
7
zhady009 OP 数据是写进去了..不太理解
|
8
gejun123456 2019-05-22 10:15:48 +08:00
@zhady009 #7 用了啥 mybatis 插件么,我这边不会出现这个问题的
|
9
gejun123456 2019-05-22 10:16:39 +08:00
@zhady009 #7 看看 有没有插件用了 replaceAll 啥的 https://jerval.iteye.com/blog/2164227
|
10
gejun123456 2019-05-22 10:18:14 +08:00 1
|
11
zhady009 OP @gejun123456 感谢找到原因了
|