实体Bean类:ApplicationUrlBean
/** * ApplicationUrlBean.java * * 功能:应用系统UrlBean类 * 类名:ApplicationUrlBean * * ver 变更日 部门 开发者 变更内容 * ───────────────────────────────────────────────────── * V1.00 2015-02-15 研发部 常宝龙 初版 * * Copyright (c) 2008, 2013 Infopower corporation All Rights Reserved. */ package com.syxp.yjjkService.bean; import java.util.Date; /** * 应用系统UrlBean类 * * @author 常宝龙 * */ public class ApplicationUrlBean { /** * ID */ private String id; /** * 应用名称 */ private String appName; /** * 应用编码 */ private String appCode; /** * 应用系统url */ private String appUrl; /** * 页面路径 */ private String appUrlRedirect; /** * 判断页面返回状态路径 */ private String pagePath; /** * 检修状态 */ private int overHaulStatus; /** * 检修开始时间 */ private Date overhaulStartDate; /** * 检修结束时间 */ private Date overhaulEndDate; /** * 应用级别 */ private int appLevel; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getAppName() { return appName; } public void setAppName(String appName) { this.appName = appName; } public String getAppCode() { return appCode; } public void setAppCode(String appCode) { this.appCode = appCode; } public String getAppUrl() { return appUrl; } public void setAppUrl(String appUrl) { this.appUrl = appUrl; } public String getAppUrlRedirect() { return appUrlRedirect; } public void setAppUrlRedirect(String appUrlRedirect) { this.appUrlRedirect = appUrlRedirect; } public String getPagePath() { return pagePath; } public void setPagePath(String pagePath) { this.pagePath = pagePath; } public int getOverHaulStatus() { return overHaulStatus; } public void setOverHaulStatus(int overHaulStatus) { this.overHaulStatus = overHaulStatus; } public Date getOverhaulStartDate() { return overhaulStartDate; } public void setOverhaulStartDate(Date overhaulStartDate) { this.overhaulStartDate = overhaulStartDate; } public Date getOverhaulEndDate() { return overhaulEndDate; } public void setOverhaulEndDate(Date overhaulEndDate) { this.overhaulEndDate = overhaulEndDate; } public int getAppLevel() { return appLevel; } public void setAppLevel(int appLevel) { this.appLevel = appLevel; } }
?映射Mapper类:ApplicationMapper
/** * ApplicationMapper.java * * 功能:系统探测Mapper映射类 * 类名:ApplicationMapper * * ver 变更日 部门 开发者 变更内容 * ───────────────────────────────────────────────────── * V1.00 2015-02-25 研发部 常宝龙 初版 * * Copyright (c) 2008, 2013 Infopower corporation All Rights Reserved. */ package com.syxp.yjjkService.mapper; import java.util.List; import org.apache.ibatis.annotations.Param; import com.syxp.yjjkService.bean.ApplicationUrlBean; /** * 系统探测Mapper映射类 * * @author 常宝龙 * */ public interface ApplicationMapper { /** * 获取应用系统信息 * * @return */ public List<ApplicationUrlBean> getAppUrlReference() throws Exception; }
??映射Xml文件:ApplicationMapper.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.syxp.yjjkService.mapper.ApplicationMapper"> <resultMap type="ApplicationUrlBean" id="appUrlResultMap"> <id property="id" column="id" jdbcType="VARCHAR"/> <result property="appName" column="app_name" jdbcType="VARCHAR" /> <result property="appCode" column="app_code" jdbcType="VARCHAR" /> <result property="appUrl" column="app_url" jdbcType="VARCHAR" /> <result property="appUrlRedirect" column="app_url_redirect" jdbcType="VARCHAR" /> <result property="pagePath" column="page_path" jdbcType="VARCHAR" /> <result property="overHaulStatus" column="over_haul_status" jdbcType="INTEGER" /> <result property="overhaulStartDate" column="overhaul_start_date" jdbcType="DATE" /> <result property="overhaulEndDate" column="overhaul_end_date" jdbcType="DATE" /> <result property="appLevel" column="app_level" jdbcType="INTEGER" /> </resultMap> <!-- 获取应用系统信息 --> <select id="getAppUrlReference" resultMap="appUrlResultMap"> SELECT * FROM application_url_reference </select> </mapper>
? ?配置文件:Configuration.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <typeAliases> <typeAlias type="com.syxp.yjjkService.bean.ApplicationUrlBean" alias="ApplicationUrlBean" /> <typeAlias type="com.syxp.yjjkService.bean.ApplicationUrlState" alias="ApplicationUrlState" /> </typeAliases> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://192.168.20.4:3306/yjjk" /> <property name="username" value="root"/> <property name="password" value="Syxp1111"/> </dataSource> </environment> </environments> <mappers> <mapper resource="com/syxp/yjjkService/mapper/ApplicationMapper.xml" /> </mappers> </configuration>
?? ?测试类:Test
package com.syxp.yjjkService.test; import java.io.Reader; import java.util.List; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import com.syxp.yjjkService.bean.ApplicationUrlBean; import com.syxp.yjjkService.mapper.ApplicationMapper; public class Test { private static SqlSessionFactory sqlSessionFactory; private static Reader reader; static { try { reader = Resources.getResourceAsReader("conf/Configuration.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); } catch (Exception e) { e.printStackTrace(); } } public static SqlSessionFactory getSession() { return sqlSessionFactory; } public static void main(String[] args) { new Test().checkup(); } public void checkup() { try { SqlSession session = sqlSessionFactory.openSession(); ApplicationMapper appMapper = session .getMapper(ApplicationMapper.class); List<ApplicationUrlBean> urlList = appMapper.getAppUrlReference(); System.out.println(urlList.size()); } catch (Exception e) { e.printStackTrace(); } } }
?
原文:http://a455360448201209214217.iteye.com/blog/2186754