@PathVariable和@RequestParam

2018-04-12  本文已影响0人  chen1null

简言之,就是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);

    }

}

上一篇下一篇

猜你喜欢

热点阅读