parent
f1535ef671
commit
8c438b57f6
@ -0,0 +1,22 @@
|
|||||||
|
<?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.mashibing.mapper.AirMapper">
|
||||||
|
|
||||||
|
|
||||||
|
<!-- // 查询空气质量的SQL扔Mapper里-->
|
||||||
|
<!-- List<Air> findBydDistrictId(@Param("districtId") Integer districtId);-->
|
||||||
|
<select id="findBydDistrictId" resultType="com.mashibing.entity.Air">
|
||||||
|
select
|
||||||
|
a.*,
|
||||||
|
d.name as district_name
|
||||||
|
from
|
||||||
|
air a , district d
|
||||||
|
where
|
||||||
|
a.district_id = d.id
|
||||||
|
<if test="districtId != null">
|
||||||
|
and a.district_id = #{districtId}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.mashibing.mapper;
|
||||||
|
|
||||||
|
import com.mashibing.entity.Air;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
class AirMapperTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AirMapper airMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findBydDistrictId() {
|
||||||
|
|
||||||
|
List<Air> list = airMapper.findBydDistrictId(null);
|
||||||
|
for (Air air : list) {
|
||||||
|
System.out.println(air);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue