@Select

 模糊查询:

方法一:

写在xml文件:


    <sql id="if-title-author">
        <if test="title!=null">
            title like "%"#{title}"%"
        </if>
        <if test="author!=null">
            and author=#{author}
        </if>
    </sql>

    <select id="queryBlogIF" parameterType="map" resultType="blog">
        select *
        from mybatis.blog
        <where>
            <include refid="if-title-author">

            </include>
        </where>
    </select>
   @Test
    public void queryBlogIF(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
        HashMap hashMap = new HashMap();
        hashMap.put("title","java");
        //hashMap.put("author","刘");
        List<Blog> blogs =mapper.queryBlogIF(hashMap);
        for (Blog blog : blogs) {
            System.out.println(blog);
        }
        sqlSession.close();
    }

 

方法二:1.Java代码执行的时候,传递通配符%%

<select id="getUserLike" resultType="lyt.pojo.User">
        select * from mybatis.user where name like #{value}
    </select>

    @Test
    public void getUserLike(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = mapper.getUserLike("%李%");
        for (User user : userList) {
            System.out.println(user);
        }
        sqlSession.close();
    }

 方法三:在Sql拼接中,使用通配符!

<select id="getUserLike" resultType="lyt.pojo.User">
        select * from mybatis.user where name like concat('%',#{value},'%')
    </select>

  @Test
    public void getUserLike(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = mapper.getUserLike("李");
        for (User user : userList) {
            System.out.println(user);
        }
        sqlSession.close();
    } 

 

 

 /**
     * 查询范围内雷达当前目标数据---10秒内数据
     * @param radarId
     * @param minLon
     * @param minLat
     * @param maxLon
     * @param maxLat
     * @return
     */
    @Select("select r.*,fs.mmsi from radar_record as r inner join " +
            "(select time,station from radar_record where radar_id=${radarId} and time >= now()-interval 10 second ORDER BY time desc LIMIT 1) as t on  r.time=t.time and r.radar_id=t.radar_id " +
            " left join fusion_ship as fs ON rr.radar_id = fs.radar_id AND rr.target_id = fs.target_id"+
            " where r.lat>${minLat} and r.lat<${maxLat} and r.lon>${minLon} and r.lon<${maxLon} ")
    List<RadarRecordBean> radarRecordFusionShipByRadarIdAndRegion(Long radarId,Double minLon, Double minLat, Double maxLon, Double maxLat);

    /**
     * 通过雷达id获取雷达当前目标数据---10秒内数据
     * @param radarId
     * @return
     */
    @Select("select r.*,fs.mmsi from radar_record as r inner join " +
            "(select time,station from radar_record where radar_id=${radarId} and time >= now()-interval 10 second ORDER BY time desc LIMIT 1) as t on  r.time=t.time and r.radar_id=t.radar_id " +
            " left join fusion_ship as fs ON rr.radar_id = fs.radar_id AND rr.target_id = fs.target_id")
    List<RadarRecordBean> radarRecordFusionShipByRadarId(Long radarId);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值