<!-- sql标签可以存放多条sql语句中相同的部分 -->
<sql id="common">
username,PASSWORD
</sql>
<!-- include 标签-->
<select id="getUserByConditionSql" resultType="Map" parameterType="Map">
SELECT <include refid="common"/> FROM users WHERE username=#{username} AND PASSWORD=#{password}
</select>
<select id="getUserByConditionSql2" resultType="Map" parameterType="Map">
SELECT <include refid="common"/> FROM users
</select>
/**
*sql 与 include 标签
*
* */
@Test
public void getUserByConditionSql() {
// 1、创建一个Map来封装参数
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("username", "北京");
paramMap.put("password", "8888");
Map<String, Object> userMap = session.selectOne("cn.liwen.impl.UserDaoImpl.getUserByConditionSql", paramMap);
System.out.println(userMap);// null
}
@Test
public void getUserByConditionSql2() {
// 1、创建一个Map来封装参数
List<Map<String, Object>> userList = session.selectList("cn.liwen.impl.UserDaoImpl.getUserByConditionSql2");
System.out.println(userList);
}