mybatis知识点

1. #{} 和 ${}的区别

  •    #{} 在sql中相当于一个参数站位符,会对传进来的参数加上单引号,会经过PreparedStatement编译,能防住sql注入,一般用来传入参数。
  • ${} 一个静态站位符,传进来什么就是什么,一般用来传入表名,或者是要显示的字段

2、当实体类中的属性名和表中的字段名不一样 ,怎么办 ?

第1种: 通过在查询的sql语句中定义字段名的别名,让字段名的别名和实体类的属性名一致 
    <select id=”selectorder” parametertype=”int” resultetype=”me.gacl.domain.order”> 
       select order_id id, order_no orderno ,order_price price form orders where order_id=#{id}; 
    </select> 
第2种: 通过<resultMap>来映射字段名和实体类属性名的一一对应的关系 
    <select id="getOrder" parameterType="int" resultMap="orderresultmap">
        select * from orders where order_id=#{id}
    </select>
   <resultMap type=”me.gacl.domain.order” id=”orderresultmap”> 
        <!–用id属性来映射主键字段–> 
        <id property=”id” column=”order_id”> 
        <!–用result属性来映射非主键字段,property为实体类属性名,column为数据表中的属性–> 
        <result property = “orderno” column =”order_no”/> 
        <result property=”price” column=”order_price” /> 
    </reslutMap>

5.mysql 主从复制数据延迟
原因:因为mysql是单线程,salve可能在做ddl,dml,阻塞了线程1分钟,那么主库复制到从库就可能存在延迟。

posted @ 2018-11-22 20:17  英特费斯  阅读(108)  评论(0编辑  收藏  举报