结对作业开发进度(第六天)
第六天进行某些mapper文件中sql语句的书写,以及对逻辑进行分析
mapper文件
1 package com.mapper; 2 3 import com.pojo.ditiepojo; 4 import com.pojo.huanc; 5 import com.pojo.zhandian; 6 import org.apache.ibatis.annotations.Insert; 7 import org.apache.ibatis.annotations.Param; 8 import org.apache.ibatis.annotations.Select; 9 10 import java.util.List; 11 12 public interface ditieMapper { 13 @Select("select * from ditie1") 14 List<ditiepojo> selectAll(); 15 List<ditiepojo> tiaocha(ditiepojo ditiepojo); 16 List<ditiepojo> selectByPageAndCondition(@Param("begin") int begin, @Param("size") int size, @Param("ditiepojo") ditiepojo ditiepojo); 17 18 /** 19 * 根据条件查询总记录数 20 * @return 21 */ 22 int selectTotalCountByCondition(ditiepojo ditiepojo); 23 //导入地铁信息 24 @Insert("insert into ditie1 values(#{xianlu},#{cid},#{zhandian},#{huanc},null)") 25 void add(ditiepojo ditiepojo); 26 @Select("select *from ceshi1") 27 List<zhandian> select(); 28 //导入换成信息 29 @Insert("insert into xjiao values (#{xianlu1},#{xianlu2},#{gzhandain})") 30 void add1(huanc huanc); 31 @Select("select * from ditie1 where zhandian=#{zhandian}") 32 ditiepojo lix(@Param("zhandian")String zhandian); 33 //查询起始点的信息 34 @Select("select * from ditie1 where zhandian=#{zhandian}") 35 36 List<ditiepojo> qzcha(@Param("zhandian")String zhandian); 37 @Select("select * from ditie1 where zhandian=#{zhandian} and xianlu=#{xianlu}") 38 ditiepojo qzchass(@Param("zhandian")String zhandian,@Param("xianlu")String xianlu); 39 @Select("select * from ditie1 where xianlu=#{xianlu}") 40 41 ditiepojo xzcha(@Param("xianlu")String xianlu); 42 @Select("select * from ditie1 where id=#{id}") 43 ditiepojo idcha(@Param("id")int id); 44 //查询换乘 45 @Select("select * from xjiao where xianlu1=#{xianlu1}") 46 List<huanc> hcha(@Param("xianlu1")String xianlu1); 47 @Select("select * from xjiao where xianlu1=#{xianlu1} and xianlu2=#{xianlu2}") 48 huanc licha(@Param("xianlu1")String xianlu1,@Param("xianlu2")String xianlu2); 49 @Select("select * from ditie1 where huanc=#{huanc}") 50 List<ditiepojo>cha0(@Param("huanc")String huanc); 51 @Select("select * from ditie1 where xianlu=#{xianlu}") 52 List<ditiepojo>xianlu(@Param("xianlu")String xianlu); 53 }
mapper.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > 3 <mapper namespace="com.mapper.ditieMapper"> 4 <select id="tiaocha" resultType="com.pojo.ditiepojo"> 5 select * from ditie1 6 <where> 7 <if test="xianlu != null and xianlu != '' "> 8 and xianlu like #{xianlu} 9 </if> 10 11 <if test="zhandian != null and zhandian != '' "> 12 and zhandian like #{zhandian} 13 </if> 14 </where> 15 </select> 16 <select id="selectByPageAndCondition" resultType="com.pojo.ditiepojo"> 17 select * from ditie1 18 <where> 19 <if test="ditiepojo.xianlu != null and ditiepojo.xianlu != '' "> 20 and xianlu like #{ditiepojo.xianlu} 21 </if> 22 23 <if test="ditiepojo.zhandian != null and ditiepojo.zhandian != '' "> 24 and zhandian like #{ditiepojo.zhandian} 25 </if> 26 </where> 27 limit #{begin} , #{size} 28 </select> 29 <select id="selectTotalCountByCondition" resultType="java.lang.Integer"> 30 select count(*) from ditie1 31 <where> 32 <if test="xianlu != null and xianlu != '' "> 33 and xianlu like #{xianlu} 34 </if> 35 36 <if test="zhandian != null and zhandian != '' "> 37 and zhandian like #{zhandian} 38 </if> 39 </where> 40 </select> 41 </mapper>