Spring Parameter Binding Question

Asked 2 years ago, Updated 2 years ago, 79 views

@RequestMapping(value="/read", method = RequestMethod.GET)
    public void read(Model model,@RequestParam("bno") int bno)throws Exception{

        logger.info ("read call");
        model.addAttribute(service.read(bno));
    }

    @RequestMapping(value="/modify", method = RequestMethod.GET)
    public void updateGET(Model model, int bno)throws Exception{

        logger.info ("call to modify page");
        model.addAttribute(service.read(bno));
    }

@RequestMapping(value="/modify", method = RequestMethod.POST)
    public String updatePOST(Model model, BoardVO vo)throws Exception{

        logger.info ("execute the modify function");
        service.update(vo);
        return "redirect:/board/listAll";
    }

@RequestMapping(value="/read", method = RequestMethod.GET)
    public void read(@RequestParam("bno") int bno, 
            @ModelAttribute("cri")Criteria cri,
            Model model)
    throws Exception{

        model.addAttribute(service.read(bno));
    }

I'm practicing crud on the bulletin board The data sent by the user must be received from the server and converted according to the data type But when I read the book, it converts some things into @RequestParam You don't have to use an annotation. You don't have to use it as an int The same goes for objects Is there any pros and cons or is it because the spring version is omitted as it goes up?

spring

2022-09-22 22:11

2 Answers

With RequestParam annotation, you can perform various processing of parameters.

This means that the parameter name is "flag" and must come. The value of the parameter is stored in the flag variable.

Declaring it as above, This means that the parameter name is "pageNo" and must come. If the parameter is not passed, the default value is 1. The value of the parameter is stored in the flag variable.

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html

I think it would be better if you refer to it.


2022-09-22 22:11

In general, local (IDE) developments do not use @RequestParam and use parameters to bind properly.

However, there are times when you deploy it to a server and you get an error.

You can think of it as the same case as the link below, and I recommend you to put it on when developing it by general developers.

@RequestParam(value="param1", required=false) Integerparam1

https://m.blog.naver.com/PostView.nhn?blogId=sm_woo&logNo=70185755273&categoryNo=54&proxyReferer=&proxyReferer=https%3A%2F%2Fwww.google.co.kr%2F


2022-09-22 22:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.