mybatis学习(02)


1:environment 这个是配置数据源,我们现在之配置一个。
   使用哪个数据源 直接在 environments有个default=“这个数据源的id”就可以了。

2:no bound  这个就是你 dao接口里的方法和 mapper.xml文件里的id没有匹配 

3: mapper文件里面使用了 update  insertinto  delete ,那么在dao接口里面方法返回只能是int

4:模糊查询如果是中文,可能会乱码,那么在数据源的链接后面加上

?useUnicode=true&characterEncoding=utf-8

5:openSession(true),这样写可以不是使用commit,自动提交事务

6:parameterMap这个属性已经废弃掉了,不推荐使用,或者你根本就不知道就可以。

注意:
1:要把mybatis的数据源改成配置版本 
   使用了mybatis总配置文件里面的 properties属性
     <properties resource="jdbc.properties"></properties> 
2:<!-- 请别名用 -->
  <typeAliases>
   <typeAlias type="com.zlt.entities.Student" alias="stu"/>
  </typeAliases>

3:针对单一参数,mybatis 提供了一个内置参数的使用_parameter
       <select id="findByName" parameterType="String" resultType="com.hmy.pojo.Student">
        <bind name="bindname" value="'%'+_parameter+'%'"/>
        SELECT * from student where name like #{bindname}
    </select>

4:@Insert @Select @Delete @Update

5:一对多 和 一对一
   一对多:
    《collection》 还有一个ofType 多这方使用的是什么类型。 
  一对一
     《association》 javaType

猜你喜欢

转载自blog.csdn.net/weixin_41417585/article/details/87633091
今日推荐