mapper.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.xxx.dao.CityHospitalDao"> <!-- 根据某字段查询所有 --> <select id="getHospitalByType" resultType="com.xx.entity.CityHospitalEntity" parameterType="String"> select * from hospital <!-- 非空判断,无数据查询所有 --> <if test="type != null and type != '' "> where type = #{type} </if> </select> </mapper>
dao接口:
import java.util.List; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.xxx.city.entity.CityHospitalEntity; @Mapper public interface CityHospitalDao extends BaseMapper<CityHospitalDao>{ List<CityHospitalEntity> getHospitalByType(@Param("type") String type); }