Mybatis学习——动态sql
在mapper.xml文件中使用
....
<?xml version="1.0" encoding="UTF-8" ?> DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://www.mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="xyz.javaswing.mapper.UserMapper"> <select id="findUserById" parameterType="int" resultType="user"> select * from user where id = #{id} select> <select id="findUser" parameterType="user" resultType="user"> select * from user <where> <if test="id!=0"> id = #{id} if> <if test="username!=null"> username = #{username} if> <if test="password!=null"> password = #{password} if> where> select> mapper>