@RequestMapping (method = RequestMethod.GET,value= "/{provinceId}_{levelId}.htm" ) public Map<String, Appointment> test() { return appointmentBook.getAppointmentsForToday(); } @RequestMapping (method = RequestMethod.GET,value= "/{provinceId}_{levelId}_s{id}.htm" ) public Map<String, Appointment> test1() { return appointmentBook.getAppointmentsForToday(); } |
As with the above two URLs, when I enter /2_3_s1.htm on the browser (here omitting the thing in front of the URL), I always enter the first method, and the order of your two methods is also the same, always enter the first method. One, the problem is not difficult to see. In fact, the first URL contains the first one. Both methods of the request link of /2_3_s1.htm are consistent (equivalent to treating 3_s1 as a whole, so the first method is also consistent). As for why it entered the first One, it should be that the first URL contains the second, which is equivalent to a parent-child relationship.
Solution:
Change the first method to the following
1
2
3
4
|
@RequestMapping (method = RequestMethod.GET,value= "/{provinceId}_{levelId:\\d*}.htm" ) public Map<String, Appointment> test() { return appointmentBook.getAppointmentsForToday(); } |
It is to add \\d* after levelId, which means that levelId can only match integers. If written in this way, our previous link/2_3_s1.htm will enter the second method, because you treat 3_s1 even as A link does not meet the condition of an integer, so it will enter the second method.
\\d{6}: Represents 6 digits
\\?-[0,9]d: Represents a negative integer
[az]{3}: Three letters,
etc.
Read More:
- [Solved] SpringMVC Shiro Error: org.apache.shiro.UnavailableSecurityManagerException No SecurityManager
- [Solved] Circular view path [index]: would dispatch back to the current handler URL [] again. Che
- Error querying database. Cause: java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is no
- [Solved] init datasource error, url: jdbc:mysql://localhost:3306/test
- [Solved] Failed to configure a DataSource: ‘url‘ attribute is not specified…bug
- [Solved] SpringBoot Microservices: Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded dat
- [Solved] SpringBoot+Dubbo Startup Error: Fail to start server(url dubbo192.168.0.920880service
- [Solved] SpringBoot+Dubbo Startup Error: Fail to start server(url: dubbo://192.168.0.9:20880/service
- idea Error: Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource
- [Solved] Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource
- [Solved] Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could [Solved]
- Failed to auto-configure a DataSource: ‘spring.datasource.url‘ is not specified and no embedded data
- [Solved] init datasource error, url: xxxjava.sql.SQLRecoverableException: IO ERROR: Undefined Error
- [Solved] “status“:405,“error“ Request method ‘POST‘ not supported“
- How to convert a Java string into a number (stringtonumber)
- The precision of decimal calculation with double and float in Java is not accurate
- Spring boot uses thread pool to realize asynchronous processing without return and asynchronous processing with return
- Xdoc generates API documents based on Java annotations
- Java error prompt….. cannot be resolved