- <mapper namespace="com.wztx.java">
- <resultMap id="resultMap" type="java.util.HashMap">
- <result property="customer_id" column="customer_id"/>
- <result property="customer_name" column="customer_name"/>
- <result property="address" column="address"/>
- <result property="cs_tele" column="cs_tele"/>
- <result property="username" column="username"/>
- <result property="codeitem_name" column="codeitem_name"/>
- <result property="createTime" column="createTime"/>
- </resultMap>
- <select id="selectlimit" resultMap="resultMap">
- select
- a.customer_id,
- a.customer_name,
- a.address,
- a.cs_tele,
- b.username,
- c.codeitem_name,
- a.createTime
- from
- tbl_crm_customer a
- LEFT JOIN
- tbl_comp_user b on a.forUser=b.user_id
- LEFT JOIN
- tbl_crm_codeItem c on a.customer_status=c.code_item_id
- order by
- a.createTime DESC
- limit
- #{begin},#{sum};
- </select>
- </mapper>
config:
- <?xml version="1.0" encoding="gbk"?>
- <!DOCTYPE configuration
- PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-config.dtd">
- <configuration>
- <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://139.210.36.220:3306/crm"/>
- <property name="username" value="root"/>
- <property name="password" value="smartlbs2012DB"/>
- </dataSource>
- </environment>
- </environments>
- <mappers>
- <mapper resource="com/wztx/java/customer.xml"/>
- </mappers>
- </configuration>
- /**
- * 查询所有的信息
- * @param nowpage
- * @param sum
- * @param c_name
- * @return
- */
- public List selectAllCustomer(int nowpage,int sum){
- SqlSession session = null;
- List list=null;
- try {
- session = DbSessionFactory.getSqlSessionFactory().openSession();
- Map<String,Object> map=new HashMap<String,Object>();
- map.put("begin",nowpage);
- map.put("sum", sum);
- list = (List)session.selectList("com.wztx.java.selectlimit",map);
- session.commit();
- } catch (Exception e) {
- e.printStackTrace();
- }finally {
- session.close();
- }
- return list;
- }
- response.setContentType("text/html;charset=GBK");
- response.setContentType("text/json;charset=GBK");
- request.setCharacterEncoding("GBK");
- PrintWriter out = response.getWriter();
- String page =request.getParameter("nowPage");
- String sum = request.getParameter("rows");
- int nowPage = Integer.parseInt(page);
- int rows = Integer.parseInt(sum);
- QueryDao querydao = new QueryDao();
- ArrayList<Map> al =(ArrayList<Map>) querydao.QueryAllCustomer(nowPage,rows);
- for(int i =0;i<al .size();i++){
- Map m = (Map)al.get(i);
- System.out.println(m.get("customer_name"));
- }
取出所有的结果集。可以继续扩展分页功能。