zoukankan      html  css  js  c++  java
  • 使用MyBatis 框架犯的错误

    最近做项目,数据层使用的是MyBatis框架,在使用过程中,犯了一些错误:

    resultMap和resultType书写错误导致问题

    resultMap和resultType二者用法不一样:

    resultType:

    <select id="count" parameterType="AreaDto"
     resultType="java.lang.Integer">  
            SELECT count(*) FROM USER  
    </select>  
    

    resultMap:

    <resultMap type="com.liulanghan.Blog" id="BlogResult">    
        <id column="id" property="id"/>    
        <result column="title" property="title"/>    
        <result column="content" property="content"/>    
        <result column="owner" property="owner"/>    
    </resultMap>   
    
    <select id="selectBlog" parameterType="int" resultMap="BlogResult">    
          select * from t_blog where id = #{id}    
    </select>  

    resultType值可以指定很多类型,包括一个类。

    jdbcType中的int类型为INTEGER

    Mybatis中javaType和jdbcType对应关系:

    jdbcTypejavaType
    CHAR String
    VARCHAR String
    BOOLEAN boolean
    INTEGER int
    FLOAT double
    DOUBLE double



    在insert语句中,values后忘了加#{ },直接属性上去了。

    <insert id="add" parameterType="EStudent">
      insert into TStudent(name, age) values(#{name}, #{age})
    </insert>

    values后面的值是相应类对应的属性值,还可以对这些属性指定jdbcType :

    <insert id="insert"  parameterType="com.examples.Role">
            insert into role ( id,name,type) values 
            (
             #{id,jdbcType=CHAR},
             #{name,jdbcType=VARCHAR},
             #{type,jdbcType=CHAR}
            )
        </insert>
  • 相关阅读:
    【linux 高级网络应用】1,2-企业IP规划部署实战,ip地址和子网划分
    【linux CCNP】4,5-linux网络及OIS-TCP/IP
    【linux CCNP】3-linux网络抓包和TCP三次握手
    【linux CCNA】1和2-linux网络基础知识入门 与 tcp协议
    CephFS文件储存
    OSD纵向扩容
    CEPH之对象存储
    CEPH之块存储
    ceph_dashboard
    ceph 创建和删除osd
  • 原文地址:https://www.cnblogs.com/bigdata1024/p/8387427.html
Copyright © 2011-2022 走看看