ibatis的CURD

duruiyang603發表於2015-09-18
繼承 org.springframework.orm.ibatis.support.SqlMapClientDaoSupport類
例如:
public class UserLoginDao extends SqlMapClientDaoSupport(){

 public UserInfo getItemById(String userId) {
  Map<String, String> params = new HashMap<String, String>(1);
  params.put("userId", userId);
  return (UserInfo) getSqlMapClientTemplate().queryForObject(user.getItemById params);
    }


同時建立sqlMap 配置檔案 :

<sqlMap namespace="user">

  <sql id="select_xxx_user">
           select xxx.user_id,xxx.login,xxx.mobile FROM GOME_USER gome
   </sql> 

 <select id="getItemById" resultMap="UserInfo" parameterClass="java.util.Map">
  <include refid="select_xxx_user"/>
  <![CDATA[
     where USER_ID=#userId# and removed IS NULL
  ]]>
 </select>

</sqlMap>

相關文章