Mybatis单个参数的if判断(针对异常:There is no getter for property..)------mybatis的内置对象

这里有一个删除方法:

int deleteByPrimaryKey(Integer id);
然后对应的sql的xml如下:
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  delete from tablename
  where id = #{id,jdbcType=INTEGER}
</delete>
以上是单个参数一般的写法。
但是如果我下面的同样也是单个参数,但是且报错了:There is no getter for property..!!
DAO:
List<Article> recommandList( Integer siteid);
XML:
<select  id="recommandList" resultMap="BaseResultMap">

  SELECT a.*  from article a where a.id in
  (SELECT atr.article_id from article_tags_relation atr where isdelete =0)
  <if test="siteid !=0">
  and a.article_type_id = #{siteid,jdbcType=INTEGER}
  </if>
  ORDER BY a.publish_time desc

</select>

为什么呢?因为if里面用了mybatis的内置对象,例如这里:“ <if test="siteid !=0">”

解决方式一:
DAO:
List<Article> recommandList(@Param("siteid") Integer siteid);
如上修改,给siteid @Param注入getter 即可。解决方式二:将 <if test...> 判断里参数换成_parameter即可

原文地址:https://www.cnblogs.com/huangjinyong/p/11775113.html

时间: 2024-07-29 10:07:07

Mybatis单个参数的if判断(针对异常:There is no getter for property..)------mybatis的内置对象的相关文章

Mybatis单个参数的if判断(针对异常:There is no getter for property..)

我们都知道mybatis在进行参数判断的时候,直接可以用<if test=""></if> 就可以了,如下: 1.常规代码 <update id="update" parameterType="com.cq2022.zago.order.entity.Test" > update t_test_l <set > <if test="trnsctWayId != null"

mybatis 异常 There is no getter for property named &#39;bizId&#39; in &#39;class java.lang.Long&#39;

mybatis 异常 There is no getter for property named 'bizId' in 'class java.lang.Long' 当使用mybatis进行传参的时候,参数只有一个时会出现这种类似的错误. 解决: 1.接口定义出,指定参数名 2.在xml 中指定类型 mybatis 异常 There is no getter for property named 'bizId' in 'class java.lang.Long'

javaScript之分支判断与内置对象

一,分支结构 单一选择结构(if) 二路选择结构(if/else) 内联三元运算符 ?: 多路选择结构(switch) var condition = true; if (condition) { alert("我将出现!"); } condition = false; if (condition) { alert("我不会出现!"); } else { alert("我会出现!"); } condition ="some string

Mybatis 传入List类型参数,报错:There is no getter for property named &#39;__frch_item_0&#39; in

错误如下: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '__frch_item_0' in 'class com.asiacloud.core.model.PageModel' at org.mybatis.spring.MyBatisEx

Servlet接口中的参数对象、JSP、EL表达式的内置对象罗列

Servlet接口参数对象: ServletRequest:service() 方法的参数 ServletResponse:service()方法的参数 ServletConfig:init()方法的参数 JSP九个内置对象: request                请求对象       类型javax.servlet.ServletRequest   作用域Request response              响应对象       类型javax.servlet.ServletRe

使用内部枚举类作为外部类的参数的Mybatis的参数该如何判断

新写了一个接口,期望根据不同的参数来给数据库中不同的字段进行传值.这里使用了内部静态枚举类的方式进行传值,在写mybatis动态sql时,如果是普通对象,一般使用,那么使用枚举类,如何判断枚举类的值呢? Mapper接口 public class SLineSboxesQueryParam { private QueryMethod queryMethod;//查询方式的枚举内部类 private List<String> idList; private LocalDateTime start

There is no getter for property named &#39;user&#39; in &#39;class com.jyr.wh.domain.User&#39; 异常

今天在使用mybatis时,出现了一个问题:There is no getter for property named 'user' in 'class com.jyr.wh.domain.User,现记录下来 使用注解的形式写sql语名,参数为一个对象 以下为正确写法: @Insert( "INSERT INTO t_user(openId,nickName,gender,language,city,province,country," + "avatarUrl,union

mybatis 的参数处理

1.接口中传递参数不同数量时的情况处理: a.单个参数的情况: mybatis不会做特殊处理,可以使用 #{参数名/任意名}:取出参数值.(可以看到上面的输出结果没有任何问题.) b.多个参数的情况: 如果按照上面的方式指定,即如下图所示,会出异常.(这样截图太多,不写地太过详细) 注:可以看到,异常报错提示中,只能够以索引值或者 param1,param2,... 的方式来指定. c.命名参数的形式指定:在指定的方法中添加 @Param("指定参数名") 注解即可.(可以看到下面的输

mybatis 单一参数时的动态语句

多参数时,可以传对象或封装成map public void getBookList(String publisher,String author){ Map<String,Object> maps = new HashMap<String, Object>(); maps.put("publisher", publisher); maps.put("author", author); this.getListByEntity("ge