in Education by
I was wondering if I can customize my url into controller to accept null values @RequestMapping( value = "foo/{y}/{x}", method = RequestMethod.GET) public ModelAndView doSmth(@PathVariable(value = "x") String x, @PathVariable(value = "y") String y) { } Here in my case , X , Y can be empty string . How could I manage smth like that to let this method on the controller to handle this url ? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If you want to support optional values, then path variables aren't well suited. Request parameters (using @RequestParam) are a better idea, since they easily support optional values using the required attribute. If you really want to support optional path variables, then you need to overload your mappings, i.e. @RequestMapping(value = "foo/{y}/{x}") public ModelAndView doSmth(@PathVariable(value = "x") String x, @PathVariable(value = "y") String y) @RequestMapping(value = "foo/{y}") public ModelAndView doSmth(@PathVariable(value = "y") String y) @RequestMapping(value = "foo") public ModelAndView doSmth()

Related questions

0 votes
    I'm teaching myself the Spring Cloud Config Server and having some trouble with injecting the properties into ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I want have a setup of redis where I write to master and read from slave, without any sentinel. I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have an Enum package com.javarnd.bbms.enums; public enum BloodTypeEnum { A_PLUS(1, "A+"), ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    first of all,i am fairly new with spring mvc so .. how springmvc find the right class to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    Is it necessary to keep Spring MVC in the classpath for developing RESTful web services?...
asked Jun 24, 2021 in Technology by JackTerrance
0 votes
0 votes
    What does MVC pattern stands for? (a) Mock View Control (b) Model view Controller (c) Mock View Class (d) ... Beans & JDBC of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    What does MVC pattern stands for? (a) Mock View Control (b) Model view Controller (c) Mock View ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    What is MVC pattern?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    Which type of remote URL does not require your user-name and password while for cloning or pushing? A. SSH url B. Https Url...
asked Dec 17, 2022 in Technology by JackTerrance
0 votes
    Good Day All I am completely new to this type of query but is it possible to define a url on a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I had to add some ugly links in my website that looks like: "/page/?utm_source=value&utm_source= ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    In the context of computing, what is the full form of URL ? 1. Undistributed Resource Locator 2. Unified Resource Locator 3. Uniform Resource Locator 4. Uniform Region Locator...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I have many automated integration tests. Some of them are negative-case tests, which make sure that my ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I need to check if url exists and can be reached. In order to do it I send Get request and ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 23, 2022 in Education by JackTerrance
...