2023-06-06
原文作者:惑边 原文地址:https://blog.csdn.net/my_momo_csdn

接口方法定义

       List<Player> findPlayer1(Map<String, Object> queryMap);
       List<Player> findPlayer3(PlayerQueryBean playerQueryBean);
       List<Player> findPlayer2(@Param("team") String team, @Param("height") Float height);

一、注解的方式

       // 第二种方式直接使用参数
       String team = "Laker";
       Float height = 1.98F;
       List<Player> list2 = mapper.findPlayer2(team, height);
       System.out.println(list2);
       
        Mapper文件:
        <select id="findPlayer2" resultType="Player">
                select  *
                from tb_player a
                where a.team = #{team} and
                a.height = #{height}
            </select>

二、Map的方式

        // 第一种方式使用map
        String team = "Laker";
        Float height = 1.98F;
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("team", team);
        params.put("height", height);
        List<Player> list1 = mapper.findPlayer1(params);
        System.out.println(list1);
        
        
        Mapper文件:
        <select id="findPlayer1" resultType="Player"
                    parameterType="map">
                select *
                from tb_player a
                where a.team = #{team} and
                a.height = #{height}
            </select>

三、Bean的方式

         // 第三种方式用对象
         String team = "Laker";
        Float height = 1.98F;
        PlayerQueryBean playerQueryBean = new PlayerQueryBean();
        playerQueryBean.setTeam(team);
        playerQueryBean.setHeight(height);
        List<Player> list3 = mapper.findPlayer3(playerQueryBean);
        System.out.println(list3);
        
        Mapper文件:
        <select id="findPlayer3" resultType="Player"
              parameterType="com.intellif.mozping.querybean.PlayerQueryBean">
            select  *
            from tb_player a
            where a.team = #{team} and
            a.height = #{height}
        </select>
阅读全文