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>
  • 相关阅读:
    python2 类型转换和数值操作
    python2 实现的LED大数字效果
    Python2 基础语法(三)
    delphi操作ini文件
    [SQL]数据库还原 42000错误
    我的宝宝来了
    [DELPHI] D2009控件的安装
    DELPHI学习过程和函数
    [SQL][转载]SQL优化索引
    [SQL] SQL语句,存储过程执行时间
  • 原文地址:https://www.cnblogs.com/bigdata1024/p/8387427.html
Copyright © 2011-2022 走看看