What is the difference between /* and /** pattern in Spring boot?

后端 未结 3 1483
自闭症患者
自闭症患者 2021-02-14 14:50

I was trying to register certain URLs for a Filter when I noticed that there is a difference between /* and /** patte

3条回答
  •  梦谈多话
    2021-02-14 15:19

    IMHO code worths 100 words in this case:

    import org.junit.Assert.assertFalse
    import org.junit.Assert.assertTrue
    import org.junit.Test
    import org.springframework.util.AntPathMatcher
    
    class AntPathMatcherTests {
        @Test
        fun twoAsterisks() {
            val pattern = "/api/balance/**"
    
            val matcher = AntPathMatcher()
            val matching = { path: String -> matcher.match(pattern, path) }
    
            assertTrue(matching("/api/balance"))
            assertTrue(matching("/api/balance/"))
            assertTrue(matching("/api/balance/abc"))
            assertTrue(matching("/api/balance/abc/"))
            assertTrue(matching("/api/balance/abc/update"))
    
            assertFalse(matching("/api/bala"))
        }
    
        @Test
        fun oneAsterisk() {
            val pattern = "/api/balance/*"
    
            val matcher = AntPathMatcher()
            val matching = { path: String -> matcher.match(pattern, path) }
    
            assertTrue(matching("/api/balance/"))
            assertTrue(matching("/api/balance/abc"))
    
            assertFalse(matching("/api/bala"))
            assertFalse(matching("/api/balance"))
            assertFalse(matching("/api/balance/abc/"))
            assertFalse(matching("/api/balance/abc/update"))
        }
    }
    

提交回复
热议问题