用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来判断来的
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 ;
List<Module> queryByParentCode(@Param(value="parentCode") String parentCode) throws Exception ;
恩 谢谢了 问题解决了 就是这样的