mybatis 初识2
来源:互联网 发布:单片机蜂鸣器报警电路 编辑:程序博客网 时间:2024/06/05 06:33
关联关系 :相对应参数,再查找一次
<resultMap type="Student" id="StudentResult"><id property="id" column="id"/><result property="name" column="name"/><result property="age" column="age"/><association property="address" column="addressId" select="com.java1234.mappers.AddressMapper.findById"></association><association property="grade" column="gradeId" select="com.java1234.mappers.GradeMapper.findById"></association></resultMap>
动态sql:
样例:
<mapper namespace="com.java1234.mappers.StudentMapper"><resultMap type="Student" id="StudentResult"><id property="id" column="id"/><result property="name" column="name"/><result property="age" column="age"/></resultMap><insert id="insertStudent" parameterType="Student">insert into t_student values(null,#{name},#{age},#{pic},#{remark});</insert><select id="getStudentById" parameterType="Integer" resultType="Student">select * from t_student where id=#{id}</select><select id="searchStudents6" resultMap="StudentResult">select * from t_student where name like #{param1} and age=#{param2}</select><select id="searchStudents" parameterType="Map" resultMap="StudentResult">select * from t_student where gradeId=#{gradeId} <if test="name!=null"> and name like #{name} </if> <if test="age!=nulll"> and age=#{age} </if></select><select id="searchStudents2" parameterType="Map" resultMap="StudentResult">select * from t_student <choose> <when test="searchBy=='gradeId'"> where gradeId=#{gradeId} </when> <when test="searchBy=='name'"> where name like #{name} </when> <otherwise> where age=#{age} </otherwise> </choose> </select><select id="searchStudents3" parameterType="Map" resultMap="StudentResult">select * from t_student <where> <if test="gradeId!=null"> gradeId=#{gradeId} </if> <if test="name!=null"> and name like #{name} </if> <if test="age!=nulll"> and age=#{age} </if> </where></select><select id="searchStudents4" parameterType="Map" resultMap="StudentResult">select * from t_student <trim prefix="where" prefixOverrides="and|or"> <if test="gradeId!=null"> gradeId=#{gradeId} </if> <if test="name!=null"> and name like #{name} </if> <if test="age!=nulll"> and age=#{age} </if> </trim></select><select id="searchStudents5" parameterType="Map" resultMap="StudentResult">select * from t_student <if test="gradeIds!=null"> <where> gradeId in <foreach item="gradeId" collection="gradeIds" open="(" separator="," close=")"> #{gradeId} </foreach> </where> </if></select><update id="updateStudent" parameterType="Student">update t_student<set> <if test="name!=null"> name=#{name}, </if> <if test="age!=null"> age=#{age}, </if></set>where id=#{id}</update></mapper>
阅读全文
0 0
- mybatis 初识2
- 初识mybatis
- 初识Mybatis
- 初识MyBatis
- 初识MyBatis
- 初识Mybatis
- 初识mybatis
- Mybatis初识
- Mybatis初识
- 初识MyBatis
- 初识MyBatis
- 初识MyBatis
- 初识Mybatis
- Mybatis初识
- 初识mybatis
- 初识mybatis
- MyBatis初识
- 初识MyBatis
- Netty(一):基础概念及消息处理流程
- Java Swing 调节图片亮度
- scala学习-scala中的元组Tuple概念
- #bzoj3393#二叉树(Splay / RMQ)
- 使用word2vec(C语言版本)训练中文语料 并且将得到的vector.bin文件转换成txt文件
- mybatis 初识2
- 入门 Webpack,看这篇就够了
- 魔法阵
- 关于事务
- 1.Java后端开发 基础入门须知!
- loadrunner 11.0 破解授权问题
- 统计字符数(POJ NO.1744)
- Android和Python之间的不能说的小秘密
- 学习一个 Bron-Kerbosch 算法