ฉันจะหาแหล่งข้อมูลเพื่อเรียนรู้รูปแบบของเส้นทางมดได้ที่ไหน ฉันไปที่ไซต์ Ant แล้ว แต่ไม่พบข้อมูลเกี่ยวกับรูปแบบเส้นทางเลย
ฉันจะหาแหล่งข้อมูลเพื่อเรียนรู้รูปแบบของเส้นทางมดได้ที่ไหน ฉันไปที่ไซต์ Ant แล้ว แต่ไม่พบข้อมูลเกี่ยวกับรูปแบบเส้นทางเลย
คำตอบ:
รูปแบบเส้นทาง Ant-style ที่ตรงกันใน กรอบสปริง:
การแมปตรงกับ URL โดยใช้กฎต่อไปนี้:
?จับคู่อักขระหนึ่งตัว*ตรงกับอักขระศูนย์หรือมากกว่า**จับคู่ 'ไดเรกทอรี' เป็นศูนย์หรือมากกว่าในเส้นทาง{spring:[a-z]+}จับคู่ regexp[a-z]+เป็นตัวแปรเส้นทางชื่อ "spring"ตัวอย่างบางส่วน:
com/t?st.jsp- ตรงกับ com / test.jsp แต่ยังcom/tast.jspหรือcom/txst.jspcom/*.jsp- จับคู่.jspไฟล์ทั้งหมดในcomไดเรกทอรีcom/**/test.jsp- จับคู่test.jspไฟล์ทั้งหมดที่อยู่ใต้comเส้นทางorg/springframework/**/*.jsp- จับคู่.jspไฟล์ทั้งหมดที่อยู่ใต้ไฟล์org/springframework pathorg/**/servlet/bla.jsp- การแข่งขันorg/springframework/servlet/bla.jspแต่ยังorg/springframework/testing/servlet/bla.jspและorg/servlet/bla.jspcom/{filename:\\w+}.jspจะจับคู่com/test.jspและกำหนดค่าtestให้กับfilenameตัวแปร
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html
spring-framework-referenceอย่างทำให้มันเป็นบริบท: https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-requestmapping-uri-templates
ฉันคิดว่าคุณหมายถึงวิธีใช้รูปแบบเส้นทาง
หากเกี่ยวกับว่าจะใช้เครื่องหมายทับหรือแบ็กสแลชสิ่งเหล่านี้จะถูกแปลเป็นตัวคั่นเส้นทางบนแพลตฟอร์มที่ใช้ระหว่างเวลาดำเนินการ
ยูทิลิตี้นี้ใช้สัญลักษณ์แทนสามตัวที่แตกต่างกัน
+----------+-----------------------------------+
| Wildcard | Description |
+----------+-----------------------------------+
| * | Matches zero or more characters. |
| ? | Matches exactly one character. |
| ** | Matches zero or more directories. |
+----------+-----------------------------------+
คำตอบที่ได้รับการโหวตมากที่สุดโดย@user11153ใช้ตารางสำหรับรูปแบบที่อ่านง่ายขึ้น
การแมปตรงกับ URL โดยใช้กฎต่อไปนี้:
+-----------------+---------------------------------------------------------+
| Wildcard | Description |
+-----------------+---------------------------------------------------------+
| ? | Matches exactly one character. |
| * | Matches zero or more characters. |
| ** | Matches zero or more 'directories' in a path |
| {spring:[a-z]+} | Matches regExp [a-z]+ as a path variable named "spring" |
+-----------------+---------------------------------------------------------+
ตัวอย่างบางส่วน:
+------------------------------+--------------------------------------------------------+
| Example | Matches: |
+------------------------------+--------------------------------------------------------+
| com/t?st.jsp | com/test.jsp but also com/tast.jsp or com/txst.jsp |
| com/*.jsp | All .jsp files in the com directory |
| com/**/test.jsp | All test.jsp files underneath the com path |
| org/springframework/**/*.jsp | All .jsp files underneath the org/springframework path |
| org/**/servlet/bla.jsp | org/springframework/servlet/bla.jsp |
| also: | org/springframework/testing/servlet/bla.jsp |
| also: | org/servlet/bla.jsp |
| com/{filename:\\w+}.jsp | com/test.jsp & assign value test to filename variable |
+------------------------------+--------------------------------------------------------+
ในฐานะที่เป็น @ user11153 กล่าวถึงของฤดูใบไม้ผลิAntPathMatcherการดำเนินการและเอกสารพื้นฐานของมดสไตล์รูปแบบเส้นทางที่ตรงกัน
นอกจากนี้ nio API ของ Java 7 ยังเพิ่มการสนับสนุนบางอย่างในตัวสำหรับการจับคู่รูปแบบพื้นฐานผ่านFileSystem.getPathMatcher