How to set each controller a default url or requestMapping in springMVC











up vote
1
down vote

favorite












For example:the class which is a controller has a requestMapping @RequestMapping("/company") ,and it has a method named "index".
In this case,how can i input a url like '/company' or '/company/' and enter the method named "index"?










share|improve this question









New contributor




wenyang.chou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    1
    down vote

    favorite












    For example:the class which is a controller has a requestMapping @RequestMapping("/company") ,and it has a method named "index".
    In this case,how can i input a url like '/company' or '/company/' and enter the method named "index"?










    share|improve this question









    New contributor




    wenyang.chou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      For example:the class which is a controller has a requestMapping @RequestMapping("/company") ,and it has a method named "index".
      In this case,how can i input a url like '/company' or '/company/' and enter the method named "index"?










      share|improve this question









      New contributor




      wenyang.chou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      For example:the class which is a controller has a requestMapping @RequestMapping("/company") ,and it has a method named "index".
      In this case,how can i input a url like '/company' or '/company/' and enter the method named "index"?







      java spring-mvc






      share|improve this question









      New contributor




      wenyang.chou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      wenyang.chou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 5 at 3:44









      Gurwinder Singh

      32k52448




      32k52448






      New contributor




      wenyang.chou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 5 at 3:33









      wenyang.chou

      61




      61




      New contributor




      wenyang.chou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      wenyang.chou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      wenyang.chou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          There are several ways to do it. One of the example, to use @RequestMapping on method and specify request type:



          @RequestMapping(value = "/foos", method = RequestMethod.GET)
          @ResponseBody
          public String getFoos() {
          return "Get some Foos";
          }

          @RequestMapping(value = "/foos", method = RequestMethod.POST)
          @ResponseBody
          public String postFoos() {
          return "Post some Foos";
          }


          More details and examples.






          share|improve this answer





















          • I was a little wrong.thank you very much
            – wenyang.chou
            Nov 5 at 6:06


















          up vote
          0
          down vote













          You could use @RequestMapping with multiple paths like this,



          @RequestMapping(value = {"/company", "/company/"}, method = RequestMethod.GET)


          (It has String as value parameter)






          share|improve this answer





















          • this way is very well,thanks
            – wenyang.chou
            Nov 5 at 6:07











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          wenyang.chou is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147969%2fhow-to-set-each-controller-a-default-url-or-requestmapping-in-springmvc%23new-answer', 'question_page');
          }
          );

          Post as a guest
































          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          There are several ways to do it. One of the example, to use @RequestMapping on method and specify request type:



          @RequestMapping(value = "/foos", method = RequestMethod.GET)
          @ResponseBody
          public String getFoos() {
          return "Get some Foos";
          }

          @RequestMapping(value = "/foos", method = RequestMethod.POST)
          @ResponseBody
          public String postFoos() {
          return "Post some Foos";
          }


          More details and examples.






          share|improve this answer





















          • I was a little wrong.thank you very much
            – wenyang.chou
            Nov 5 at 6:06















          up vote
          0
          down vote













          There are several ways to do it. One of the example, to use @RequestMapping on method and specify request type:



          @RequestMapping(value = "/foos", method = RequestMethod.GET)
          @ResponseBody
          public String getFoos() {
          return "Get some Foos";
          }

          @RequestMapping(value = "/foos", method = RequestMethod.POST)
          @ResponseBody
          public String postFoos() {
          return "Post some Foos";
          }


          More details and examples.






          share|improve this answer





















          • I was a little wrong.thank you very much
            – wenyang.chou
            Nov 5 at 6:06













          up vote
          0
          down vote










          up vote
          0
          down vote









          There are several ways to do it. One of the example, to use @RequestMapping on method and specify request type:



          @RequestMapping(value = "/foos", method = RequestMethod.GET)
          @ResponseBody
          public String getFoos() {
          return "Get some Foos";
          }

          @RequestMapping(value = "/foos", method = RequestMethod.POST)
          @ResponseBody
          public String postFoos() {
          return "Post some Foos";
          }


          More details and examples.






          share|improve this answer












          There are several ways to do it. One of the example, to use @RequestMapping on method and specify request type:



          @RequestMapping(value = "/foos", method = RequestMethod.GET)
          @ResponseBody
          public String getFoos() {
          return "Get some Foos";
          }

          @RequestMapping(value = "/foos", method = RequestMethod.POST)
          @ResponseBody
          public String postFoos() {
          return "Post some Foos";
          }


          More details and examples.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 5 at 3:43









          uli

          367212




          367212












          • I was a little wrong.thank you very much
            – wenyang.chou
            Nov 5 at 6:06


















          • I was a little wrong.thank you very much
            – wenyang.chou
            Nov 5 at 6:06
















          I was a little wrong.thank you very much
          – wenyang.chou
          Nov 5 at 6:06




          I was a little wrong.thank you very much
          – wenyang.chou
          Nov 5 at 6:06












          up vote
          0
          down vote













          You could use @RequestMapping with multiple paths like this,



          @RequestMapping(value = {"/company", "/company/"}, method = RequestMethod.GET)


          (It has String as value parameter)






          share|improve this answer





















          • this way is very well,thanks
            – wenyang.chou
            Nov 5 at 6:07















          up vote
          0
          down vote













          You could use @RequestMapping with multiple paths like this,



          @RequestMapping(value = {"/company", "/company/"}, method = RequestMethod.GET)


          (It has String as value parameter)






          share|improve this answer





















          • this way is very well,thanks
            – wenyang.chou
            Nov 5 at 6:07













          up vote
          0
          down vote










          up vote
          0
          down vote









          You could use @RequestMapping with multiple paths like this,



          @RequestMapping(value = {"/company", "/company/"}, method = RequestMethod.GET)


          (It has String as value parameter)






          share|improve this answer












          You could use @RequestMapping with multiple paths like this,



          @RequestMapping(value = {"/company", "/company/"}, method = RequestMethod.GET)


          (It has String as value parameter)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 5 at 4:17









          benjamin c

          1,225316




          1,225316












          • this way is very well,thanks
            – wenyang.chou
            Nov 5 at 6:07


















          • this way is very well,thanks
            – wenyang.chou
            Nov 5 at 6:07
















          this way is very well,thanks
          – wenyang.chou
          Nov 5 at 6:07




          this way is very well,thanks
          – wenyang.chou
          Nov 5 at 6:07










          wenyang.chou is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          wenyang.chou is a new contributor. Be nice, and check out our Code of Conduct.













          wenyang.chou is a new contributor. Be nice, and check out our Code of Conduct.












          wenyang.chou is a new contributor. Be nice, and check out our Code of Conduct.















           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147969%2fhow-to-set-each-controller-a-default-url-or-requestmapping-in-springmvc%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini