mybatis空格字符替换

mybatis空格字符替换

   <select id="user" resultType="java.util.Map" parameterType="java.util.Map">
        select * from user where
         <if test="password !=null and password !=''">
             `password` in
             <foreach collection="password.replaceAll('[\\[\\] ]','').split(',')" open="(" close=")" item="item" separator=",">
                 #{item}
             </foreach>
         </if>
    </select>
String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        Map<String,Object> map=new HashMap<>();
        List<String> list=new ArrayList<>(2);
        list.add("2");
        list.add("123");
        map.put("password","[2, 123]");
        List<Object> objects = sqlSession.selectList("test.user",map);
posted @ 2022-09-16 00:08  凌康  阅读(125)  评论(0编辑  收藏  举报