//TMD 写几个demo 还有大站採集
<a target=_blank href="http://hao947.com/" target="_blank">好947</a>
映射配置文件
<!-- type:映射实体类的数据类型 id:resultMap的唯一标识 -->
<RESULTMAP id=BaseResultMap type="person"><pre name="code" class="java"><a target=_blank href="http://hao947.com/" target="_blank">好947</a>
<!-- column:库表的字段名 property:实体类里的属性名 --> <ID property="personId" column="person_id" /> <RESULT property="name" column="name" /> <RESULT property="gender" column="gender" /> <RESULT property="personAddr" column="person_addr" /> <RESULT property="birthday"
column="birthday" /> </RESULTMAP>
映射配置查询语句
<!-- 当查询值得时候resultMap指定key与value。
map.put("name","项目经理")
map.put("gender" 1)<pre name="code" class="java"><a target=_blank href="http://hao947.com/" target="_blank">好947</a>
--> <SELECT id=selectPersonByParams resultmap="BaseResultMap" parametertype="java.util.Map"> select * from person p where p.name = #{name} and p.gender =#{gender} </SELECT>
映射管理库表文件
<!-- 集中管理库表的映射文件 --><pre name="code" class="java"><a target=_blank href="http://hao947.com/" target="_blank">好947</a>
<MAPPERS> <MAPPER resource="com/hao947/sql/mapper/PersonMapper.xml" /> </MAPPERS>
測试文件
@Test
public void selectPersonByParams() {
// 创建一个sqlSession <a target=_blank href="http://hao947.com" target="_blank">好947</a>
SqlSession session = sqlSessionFactory.openSession();
try {
Map<STRING, object=""> map = new HashMap<STRING, object="">();
map.put("name", "项目经理");
map.put("gender", 0);
// 第一个參数查找sql,规则namespace+"."+sql的id,第二个參数是sql要接收的參数
List<PERSON> list = session
.selectList("com.hao947.sql.mapper.PersonMapper.selectPersonByParams",map);
for (Person p : list) {
System.out.println(p);
}
} finally {
session.close();
}
}
}