jsp动态SQL语句的写法

jsp动态SQL语句的写法

问题描述:

如果现在想按id查找用户,我的sql语句为where id=?.
那么如何实现按任意列查找用户呢?就是我传进来列名和id值.sql语句如何写?

列名是指其他字段么,where id=? and 列名=?

select * from user where
    <if test="username != null">
       username=#{username}
    </if>
    <if test="username != null">
       and sex=#{sex}
    </if>