传统方法
@Controller
public class AccountController {
@Resource
private AccountService accountService;
/**
* 查询操作
* 传统的URL访问:
* http://localhost:8080/ssm/account/queryAccountById?id=1
* Restful风格 URL访问:
* http://localhost:8080/ssm/account/1
* @PathVariable 将形参设置为参数路径,声明在形参前面
* @param id
* @return
*/
@ResponseBody
// @GetMapping("account/{id}")
@RequestMapping("account/queryAccountById")
public Account queryAccountById(Integer id) {
return accountService.queryById(id);
}
}
Restful
@Controller
public class AccountController {
@Resource
private AccountService accountService;
/**
* 查询操作
* 传统的URL访问:
* http://localhost:8080/ssm/account/queryAccountById?id=1
* Restful风格 URL访问:
* http://localhost:8080/ssm/account/1
* @PathVariable 将形参设置为参数路径,声明在形参前面
* @param id
* @return
*/
@ResponseBody
@GetMapping("account/{id}")
// @RequestMapping("account/queryAccountById")
public Account queryAccountById(@PathVariable Integer id) {
return accountService.queryById(id);
}
}