@PathVariable和@RequestParam
简言之,就是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);
}
}