Mybatis学习笔记(三)

之前学的  现在用  有点gg。再仔细学一下。

动态代理开发四个原则:

(1)接口中方法名与Mapper中的id一致。

(2)namespace与接口中类的路径一致

(3)输入参数与/mapper中入参数

(4)返回值与Mapper中的ResultType一致,。


输入输出参数:

输入参数:parameterType

    简单的数据类型int String

    pojo类型

    pojo包装类

输出类型resultType

    简单类型的输出interger : resultType:可意指定将查询结果映射为pjo,但需要pojo的属性名和sql查询的列名一致。

  输出类型   ResultMap:如果sql查询字段名和pojo属性不一致可以用resultMap将字段名和属性座位一个对应关系,将查询结果映射到pojo对象中。


动态sql:

<if>

<where> :where可以去掉第一个前and:比如:

                <where>

                       <if  test="sex!=null and sex!=' ' ">

                                 and sex=#{sex}

                      </if>

                        <if test="username!=null and username!=' ' ">

                                and usernamex=#{username}

                      </if>

                </where>

           这个时候即使不写sex或者username  都不会报sql错。


sql片段:<sql>  <include>

foreach标签


关联查询

left join左表是全的 、right join右表是全的、



一对一

<association>

一对多

<collection>

    

猜你喜欢

转载自blog.csdn.net/lettyisme/article/details/80402970