美文网首页
@PathVariable和@RequestParam

@PathVariable和@RequestParam

作者: chen1null | 来源:发表于2018-04-12 14:55 被阅读0次

    简言之,就是url的参数

    @RestController

    @RequestMapping("/api")

    public class AccountsAnnotationController {

        @Autowired

        private AccountsAnnotationService accountsAnnotationService;

        // http://localhost:8081/api/account/1/1

        @RequestMapping("/account/{id}/{accountType}")

        public Accounts findAccountsByIdAndAccountType(@PathVariable("id")Long id,

                                                      @PathVariable("accountType")Long accountType) {

        System.err.println("-----> id = " + id +"\t accountType = " + accountType +" <-----");

            return  accountsAnnotationService.findAccountsByIdAndAccountType(id, accountType);

        }

        // http://localhost:8081/api/account?id=1

        @RequestMapping("/account/test")

        public Accounts findAccountsById(@RequestParam Long id) {

            System.err.println("-----> id = " + id +" <-----");

            return  accountsAnnotationService.findAccountById(id);

        }

    }

    相关文章

      网友评论

          本文标题:@PathVariable和@RequestParam

          本文链接:https://www.haomeiwen.com/subject/swnxkftx.html