Mybatis各种参数用法
2017-12-09 10:07
337 查看
1.只传单个String对象
2.传多个String对象
3.传list对象
4.传普通对象
User类:
其中test后的和大括号里的user_id都是对应User类中的字段,“=#”前面那个user_id对应user_data中的栏位
5.resultMap用法
我们平常返回的resultType为POJO类,但是有时我们只需要部分字段,那就用到resultMap替代resultType
上面的property后的user_id是对应User类中的字段,column中的user_id对应user_data中的栏位
select标签:
<select id="findUser" parameterType="String" resultType="com.example.User"> select * from user_data where sex='M' <choose> <when test="_parameter != null "> AND user_id=#{userId} </when> <otherwise> AND user_id=''</otherwise> </choose> and rownum <= 200 </select>
2.传多个String对象
<select id="findUser" resultType="User"> select * from user_data where user_id = #{0} and user_name = #{1} </select>
3.传list对象
<select id="findUsers" parameterType="java.util.List" resultType="com.example.User"> select * from user_data where sex='M' AND user_id in <foreach collection="list" item="user_id" index="index" open="(" close=")" separator=","> #{user_id} </foreach> and rownum <= 200 </select>
4.传普通对象
<select id="findUsers" parameterType="com.example.User" resultType="com.example.User"> Select* from user_data <where> <if test="user_id !=null "> user_id=#{user_id} </if> </where> </select>
User类:
public class User extends BaseResult{ public String user_id; public String user_name; public String e_mail; public String password; }
其中test后的和大括号里的user_id都是对应User类中的字段,“=#”前面那个user_id对应user_data中的栏位
5.resultMap用法
我们平常返回的resultType为POJO类,但是有时我们只需要部分字段,那就用到resultMap替代resultType
<resultMap id="userResultMap" type="com.example.User"> <result property="user_id" column="user_id"/> <result property="user_name" column="user_name"/> </resultMap
上面的property后的user_id是对应User类中的字段,column中的user_id对应user_data中的栏位
select标签:
<select id="findUsers" parameterType="com.example.User" resultMap="userResultMap"> Select* from user_data <where> <if test="user_id !=null "> user_id=#{user_id} </if> </where> </select>
相关文章推荐
- 关于向Mybatis传递多个参数进行SQL查询的用法
- 【Clojure 基本知识】 关于函数参数的各种高级用法
- Python函数的各种参数用法(含星号参数)
- Mybatis传递多个参数进行SQL查询的用法
- Oracle中自定义函数 无参数 输入参数 输出参数等各种用法
- Oracle中自定义函数 无参数 输入参数 输出参数等各种用法
- each用法、mybatis传递多个参数方法
- MessageBoxde 用法之各种参数
- Oracle中自定义函数 无参数 输入参数 输出参数等各种用法
- 《转自hfnhzpe的专栏》apt 安装和简单用法 apt-get 各种参数形式
- Mybatis传递多个参数进行SQL查询的用法
- 关于向Mybatis传递多个参数进行SQL查询的用法
- Python函数的各种参数用法(含星号参数)
- Mybatis中模糊查询的各种写法
- Wordpress get_bloginfo函数的参数及用法
- linux id命令参数及用法详解(linux查看当前登陆用户uid,gid)
- Server.Transfer 在两个窗体之间传递参数用法
- Objective-C中的@property和@synthesize用法及参数(readwrite/readonly)(assign/retain/copy)(atomicity/nonatomic)
- block作为属性,作为参数,作为返回值各种情况演示
- linux groupdel命令参数及用法详解(linux删除用户组命令)