结对作业开发进度(第七天)
第七天
对第六天中涉及到的sql对应的方法进行具体的实现
写在service文件中(接口文件)
1 package com.service; 2 3 import com.pojo.PageBean; 4 import com.pojo.ditiepojo; 5 import com.pojo.huanc; 6 import com.pojo.zhandian; 7 8 import java.util.List; 9 10 public interface ditieService { 11 List<ditiepojo> selectAll(); 12 List<ditiepojo> tiaocha(ditiepojo ditiepojo); 13 PageBean<ditiepojo> selectByPageAndCondition(int currentPage, int pageSize, ditiepojo ditiepojo); 14 void add(ditiepojo ditiepojo); 15 List<zhandian> select(); 16 void add1(huanc huanc); 17 List<ditiepojo> qzcah(String zhandian); 18 ditiepojo idcha(int id); 19 List<huanc> hcha(String xianlu1); 20 ditiepojo xzcha(String xianlu); 21 huanc licah(String xianlu1,String xianlu2); 22 ditiepojo qzchass(String zhandian,String xianlu); 23 List<ditiepojo>cha0(String haunc); 24 List<ditiepojo>xianlu(String xianlu); 25 ditiepojo lix(String zhandian); 26 27 }
service.impl
1 package com.service.impl; 2 3 import com.mapper.ditieMapper; 4 import com.pojo.PageBean; 5 import com.pojo.ditiepojo; 6 import com.pojo.huanc; 7 import com.pojo.zhandian; 8 import com.service.ditieService; 9 import com.util.SqlSessionFactoryUtils; 10 import org.apache.ibatis.session.SqlSession; 11 import org.apache.ibatis.session.SqlSessionFactory; 12 13 import java.util.List; 14 15 public class ditieimpl implements ditieService{ 16 SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory(); 17 @Override 18 public List<ditiepojo> selectAll() { 19 //2. 获取SqlSession对象 20 SqlSession sqlSession = factory.openSession(); 21 //3. 获取BrandMapper 22 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 23 24 //4. 调用方法 25 List<ditiepojo> ditiepojos = mapper.selectAll(); 26 27 //5. 释放资源 28 sqlSession.close(); 29 30 return ditiepojos; 31 } 32 33 34 35 @Override 36 public List<ditiepojo> tiaocha(ditiepojo ditiepojo) { 37 //2. 获取SqlSession对象 38 SqlSession sqlSession = factory.openSession(); 39 //3. 获取BrandMapper 40 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 41 String xianlu = ditiepojo.getXianlu(); 42 if (xianlu != null && xianlu.length() > 0) { 43 ditiepojo.setXianlu("%" + xianlu+ "%"); 44 } 45 46 String zhandian = ditiepojo.getZhandian(); 47 if (zhandian!= null && zhandian.length() > 0) { 48 ditiepojo.setZhandian("%" + zhandian+ "%"); 49 } 50 //4. 调用方法 51 List<ditiepojo> ditiepojos = mapper.tiaocha(ditiepojo); 52 53 54 //5. 释放资源 55 sqlSession.close(); 56 57 return ditiepojos; 58 } 59 60 @Override 61 public PageBean<ditiepojo> selectByPageAndCondition(int currentPage, int pageSize, ditiepojo ditiepojo) { 62 //2. 获取SqlSession对象 63 SqlSession sqlSession = factory.openSession(); 64 //3. 获取BrandMapper 65 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 66 67 68 //4. 计算开始索引 69 int begin = (currentPage - 1) * pageSize; 70 // 计算查询条目数 71 int size = pageSize; 72 73 String xianlu = ditiepojo.getXianlu(); 74 if (xianlu != null && xianlu.length() > 0) { 75 ditiepojo.setXianlu("%" + xianlu+ "%"); 76 } 77 78 String zhandian = ditiepojo.getZhandian(); 79 if (zhandian!= null && zhandian.length() > 0) { 80 ditiepojo.setZhandian("%" + zhandian+ "%"); 81 } 82 83 //5. 查询当前页数据 84 List<ditiepojo> rows = mapper.selectByPageAndCondition(begin, size, ditiepojo); 85 86 //6. 查询总记录数 87 int totalCount = mapper.selectTotalCountByCondition(ditiepojo); 88 89 //7. 封装PageBean对象 90 PageBean<ditiepojo> pageBean = new PageBean<>(); 91 pageBean.setRows(rows); 92 pageBean.setTotalCount(totalCount); 93 94 95 //8. 释放资源 96 sqlSession.close(); 97 98 return pageBean; 99 } 100 101 @Override 102 public void add(ditiepojo ditiepojo) { 103 SqlSession sqlSession = factory.openSession(); 104 //3. 获取BrandMapper 105 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 106 107 //4. 调用方法 108 mapper.add(ditiepojo); 109 sqlSession.commit();//提交事务 110 //5. 释放资源 111 sqlSession.close(); 112 } 113 114 @Override 115 public List<zhandian> select() { 116 //2. 获取SqlSession对象 117 SqlSession sqlSession = factory.openSession(); 118 //3. 获取BrandMapper 119 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 120 List<zhandian> select = mapper.select(); 121 return select; 122 } 123 124 @Override 125 public void add1(huanc huanc) { 126 SqlSession sqlSession = factory.openSession(); 127 //3. 获取BrandMapper 128 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 129 130 //4. 调用方法 131 mapper.add1(huanc); 132 sqlSession.commit();//提交事务 133 //5. 释放资源 134 sqlSession.close(); 135 } 136 137 @Override 138 public List<ditiepojo> qzcah(String zhandian) { 139 SqlSession sqlSession = factory.openSession(); 140 //3. 获取BrandMapper 141 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 142 List<ditiepojo> qzcha = mapper.qzcha(zhandian); 143 sqlSession.close(); 144 return qzcha; 145 146 } 147 148 @Override 149 public ditiepojo idcha(int id) { 150 SqlSession sqlSession = factory.openSession(); 151 //3. 获取BrandMapper 152 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 153 ditiepojo idcha = mapper.idcha(id); 154 return idcha; 155 } 156 157 @Override 158 public List<huanc> hcha(String xianlu1) { 159 SqlSession sqlSession = factory.openSession(); 160 //3. 获取BrandMapper 161 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 162 List<huanc> hcha = mapper.hcha(xianlu1); 163 sqlSession.close(); 164 return hcha; 165 } 166 167 @Override 168 public ditiepojo xzcha(String xianlu) { 169 SqlSession sqlSession = factory.openSession(); 170 //3. 获取BrandMapper 171 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 172 ditiepojo xzcha = mapper.xzcha(xianlu); 173 return xzcha; 174 } 175 176 @Override 177 public huanc licah(String xianlu1, String xianlu2) { 178 SqlSession sqlSession = factory.openSession(); 179 //3. 获取BrandMapper 180 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 181 huanc licha = mapper.licha(xianlu1, xianlu2); 182 return licha; 183 } 184 185 @Override 186 public ditiepojo qzchass(String zhandian, String xianlu) { 187 SqlSession sqlSession = factory.openSession(); 188 //3. 获取BrandMapper 189 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 190 ditiepojo qzchass = mapper.qzchass(zhandian, xianlu); 191 return qzchass; 192 } 193 194 @Override 195 public List<ditiepojo> cha0(String haunc) { 196 SqlSession sqlSession = factory.openSession(); 197 //3. 获取BrandMapper 198 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 199 List<ditiepojo> huancs = mapper.cha0(haunc); 200 return huancs; 201 } 202 203 @Override 204 public List<ditiepojo> xianlu(String xianlu) { 205 SqlSession sqlSession = factory.openSession(); 206 //3. 获取BrandMapper 207 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 208 List<ditiepojo> xianlu1 = mapper.xianlu(xianlu); 209 return xianlu1; 210 } 211 212 @Override 213 public ditiepojo lix(String zhandian) { 214 SqlSession sqlSession = factory.openSession(); 215 //3. 获取BrandMapper 216 ditieMapper mapper = sqlSession.getMapper(ditieMapper.class); 217 ditiepojo lix = mapper.lix(zhandian); 218 return lix; 219 } 220 }