Select 元素标签输出形式
- 根本数据类型
- 字符串类型
- Map 类型
- Java bean 类型
案例实操
输出参数分类
根本类型,字符串,java bean,map,数组(删除操作时体现),List(增加时体现)等每种状况定义如下
根本数据类型
Statement 定义
<!– 查问客户 –>
<select id=”queryCustomerById” parameterType=”int” resultType=”com.xxx.pojo.Customer”>
SELECT id,user_name ‘userName’,user_balance ‘userBalance’ FROM yg_customer WHERE id=#{id}
</select>
CustomerDao 办法定义
Customer queryCustomerById(int id);
字符串类型
Statement 定义
<!– 查问客户 –>
<select id=”queryCustomerByName” parameterType=”string” resultType=”com.xxx.pojo.Customer”>
SELECT id,user_name ‘userName’,user_balance ‘userBalance’ FROM yg_customer WHERE user_name=#{userName}
</select>
Dao 办法定义
Customer queryCustomerById(int id);
Map 类型
Statement 定义
<!– 输出参数为 map 类型 –>
<!– 查问客户 –>
<select id=”queryCustomerByName” parameterType=”map” resultType=”com.xxx.pojo.Customer”>
SELECT id,user_name ‘userName’,user_balance ‘userBalance’ FROM yg_customer WHERE user_name=#{userName}
</select>
Dao 办法定义
Customer queryCustomerByName(Map<String,Object> userName);
Java bean 类型
Statement 定义
<!– 输出参数为 java bean 类型 –>
<select id=”queryCustomerByParams” parameterType=”customer” resultType=”customer”>
SELECT id,user_name ‘userName’,user_balance ‘userBalance’ FROM yg_customer WHERE user_name=#{userName}
</select>
Dao 办法定义
Customer queryCustomerByParams(Customer customer);
扩大
后果类型分类
根本数据类型,字符串,JavaBean,Map,List 等
根本数据类型
Statement 定义
<!– 后果类型为根本数据 –>
<select id=”queryCustomerAccount” resultType=”int”>
select count(1) from yg_customer
</select>
Dao 办法定义与对应实现
int queryCustomerAccount();
字符串类型
Statement 定义
<!– 后果类型为字符串 –>
<select id=”queryCustomerNameById” resultType=”string” parameterType=”int”>
select user_name from yg_customer WHERE id=#{id}
</select>
Dao 办法定义
String queryCustomerNameById(int id);
Java Bean
Statement 定义
<select id=”queryUserByUser” parameterType=”user” resultType=”user”>
select id,user_name as userName,user_pwd as userPwd from user where id=#{id}
</select>
List
Statement 定义
<resultMap type=”user” id=”user_map”>
<result column=”id” property=”id”/>
<result column=”user_name” property=”userName”/>
<result column=”user_pwd” property=”userPwd”/>
</resultMap>
<sql id=”user_column”>
id,user_name,user_pwd
</sql>
<select id=”queryUserNyName2″ parameterType=”string” resultMap=”user_map”>
select <include refid=”user_column”/>
from user where user_name like concat(“%”,#{userName},”%”)
</select>
Map 类型数据
Statement 定义
<!– 后果类型为 map –>
<select id=”queryUserByIdReturnMap” parameterType=”int” resultType=”map”>
select id,user_name as userName,user_pwd as userPwd from user where id=#{id}
</select>