iteye_15993 2011-06-22 10:50
浏览 743
已采纳

Mybatis动态SQL中 参数值判断问题

用mybatis遇到了个问题。
首先上关键代码:


public interface ModuleMapper {

List<Module> queryByParentCode(String parentCode) throws Exception ;

}

Mapper.xml


<select id="queryByParentCode" parameterType="string" resultType="module">

select

m.moduleCode,m.moduleName,

m.moduleUrl,m.moduleDesc,

m.moduleIcon,m.isLeaf,

m.level,m.parent

from

module m

<where>

<choose>

<when test="parentCode != null">

m.parent = #{parentCode}

</when>

<otherwise>

m.parent is null

</otherwise>

</choose>

</where>

</select>


问题描述:我想根据传入的参数parentCode  来动态添加where子句,上面是我的思路,不知道表达式哪儿是不是这样写。然后呢 按照我这个运行就报了如下的错误:


Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'parentCode' in 'class java.lang.String'  

  我改怎样去判断那个参数呢


问题补充
carcar123 写道
parameterType="string"  ->换成Map
List<Module> queryByParentCode(String parentCode) 
String parentCode)   --> (Map qMap)

qMap.put("parentCode","xx");

再试试,这个是要用ongl来判断来的

就用String难道不可以么?如果要用Map那样不是麻烦了嘛 。可不可以直接用String的呢
问题补充
zb7503 写道
试一下:
List<Module> queryByParentCode(@Param(value="parentCode") String parentCode) throws Exception ;

恩 谢谢了 问题解决了 就是这样的
  • 写回答

2条回答 默认 最新

  • snowboy2003 2011-06-22 10:50
    关注

    试一下:
    List queryByParentCode(@Param(value="parentCode") String parentCode) throws Exception ;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大