mybatis-choose 冷不防 2022-06-02 04:22 193阅读 0赞 # mybatis-choose # @Data @ToString public class Employee { private Integer id; private String last_name; private String emaile; private String gender; private Dept dept; } <select id="getEmpByConditionIf" parameterType="com.example.demo.entity.Employee" resultType="com.example.demo.entity.Employee"> SELECT * FROM tbl_employee <!--分支选择--> <where> <choose> <when test="id!=null"> id=#{id} </when> <when test="last_name !=null "> last_name=#{last_name} </when> <when test="emaile !=null "> emaile=#{emaile} </when> <otherwise> 1=1 </otherwise> </choose> </where> </select> 总结: 分支选择 类似于java中的 switch 例如上边 id有值 按照 id查询 其他分支就不走了
还没有评论,来说两句吧...