mybatis获取主键和存储过程返回值

1: mybatis中 返回主键 :

     PasswordTO password=new PasswordTO();
            password.setWifiId(wifiId);
            password.setDeviceId(did);
            password.setPassword(pwd);
            password.setSuccessCnt(0L);
            getSqlSession().insert("password.add", password);
            return password.getId();

    

配置:
   <insert id="addWifi" useGeneratedKeys="true" keyProperty="id" parameterType="WifiTO" >
      insert into WIFI(SSID, BSSID, CREATED_DATE) values(#{ssid}, #{bssid}, now()) 
   </insert>

 

 

2:存储过程的返回值

        Map<String, Object> map=new HashMap<String, Object>();
        map.put("imei", imei);
        map.put("channelId", channelId);
        map.put("uid", "");
        getSqlSession().selectOne("user.authUser", map);
        Integer uid=(Integer)map.get("uid");
        return uid == null ? 0L : (long)uid.intValue();

配置:
  <select id="authUser" parameterType="java.util.Map" statementType="CALLABLE" resultType="java.util.Map">  
    <![CDATA[  
    {call authUser (#{imei, mode=IN, jdbcType=VARCHAR}, #{channelId, mode=IN, jdbcType=INTEGER} ,#{uid, mode=OUT, jdbcType=INTEGER})}  
    ]]>  
  </select> 

和ibats差别很大     真的很大......................

 

mybatis3.2  sqlSession支持自动类型转换

 

你可能感兴趣的:(mybatis)