import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.hx.plant.running.dao.BaseUserInfoDao;
import com.hx.plant.running.dao.DaoClient;
import com.hx.plant.running.pojo.User;
import com.hx.plant.running.bean.BaseUserInfoBean;
public class BaseUserInfoDaoImpl extends DaoClient<BaseUserInfoBean, BigDecimal> implements BaseUserInfoDao
{
@Override
public void update(BaseUserInfoBean entity) throws SQLException
{
// TODO Auto-generated method stub
}
@Override
public void save(BaseUserInfoBean entity) throws SQLException
{
// TODO Auto-generated method stub
}
@Override
public void delete(Serializable id) throws SQLException
{
// TODO Auto-generated method stub
}
/**
* 查询baseUserINfo的全部数据
*/
@Override
public List<BaseUserInfoBean> queryAll() throws SQLException
{
List<BaseUserInfoBean> baseUserInfoBeans = sqlMapClient.queryForList("queryAllBaseUserInfo");
return baseUserInfoBeans;
}
@Override
public String regist(User user)
{
Map<String, Object> params = new HashMap<String, Object>();
//这里插入相关的参数
params.put("username", user.userName);
params.put("password", user.mPsw);
System.out.println(params);
try
{
//在这里执行sql语句,相关的映射,映射对应的id为userRegest
//sqlmap为daoclient的属性,继承得到的
int update = sqlMapClient.update("userRegest", params);
// 成功
if (update == 1)
{
return "{\"result\":\"0\"}";
} else// 失败
{
return "{\"result\":\"-1\"}";
}
} catch (Exception e)
{
e.printStackTrace();
// 失败
return "{\"result\":\"-1\"}";
}
}
sqlMapConfig.xml
/**
* "
*
* @Description (TODO这里用一句话描述这个方法的作用) 查询给号码是否可以注册
* @param phoneNumber
* 手机号码
* @return false是代表可以注册,true则是已经注册了不能再进行注册
*/
public Boolean queryIsRegist(String phoneNumber)
{
Map<String, Object> params = new HashMap<String, Object>();
params.put("phoneNumber", phoneNumber);
try
{
List list = sqlMapClient.queryForList("queryThePhoneNumberIsRegist", params);
if (list.size() > 0)
{
return true;
} else
{
return false;
}
} catch (SQLException e)
{
e.printStackTrace();
}
return false;
}
}
BaseUserInfoBean.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<sqlMap resource="/ibatis/BaseUserInfoBean.xml" />
<sqlMap resource="/ibatis/BaseDeviceInfoBean.xml" />
<sqlMap resource="/ibatis/BaseUserInfo_show.xml" />
</sqlMapConfig>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
<insert id="userRegest" parameterClass="java.util.Map">
<![CDATA[
insert into BaseUserInfo (username,password) values( #username#, #password#);
]]>
</insert>
<select id="queryAllBaseUserInfo" resultClass="java.awt.List">
<![CDATA[
select * from BaseUserInfo;
]]>
</select>
<select id="queryThePhoneNumberIsRegist" resultClass="string">
<![CDATA[
SELECT count(*) FROM BaseUserInfo;
]]>
</select>
</sqlMap>