mybatis 注解的方式查询


项目中用到复杂的查询sql,选择了注解的方式@Select

加入了

@Select("select * from tlog where tid = 0

+ ""

+ "and cid=#{cid}"

+ "")

@Results({ @Result(property = "id", column = "id"),

@Result(property = "username", column = "username"),})

List getLog(Log log);

 

一直报if test这块有错,检查了一下,也没有发现有什么错。

之前写的sql都没有报错,就是因为加入了if,所有才有问题。

解决:

@Select("")

一定要加入"", 否则当作sql的一部分,而不是判断语句,导致出错。

 

注:这个是ibatis的语法,而不是ibatis plus的。