1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| @Api("用户接口") @RestController public class UserController { @Resource private UserService userService; @ApiOperation(value = "通过用户名查询用户信息", notes = "通过用户名查询用户信息", produces = "application/json") @ApiImplicitParam(name = "name", value = "用户名", paramType = "query", required = true, dataType = "String") @RequestMapping(value = "user/name", method = {RequestMethod.GET, RequestMethod.POST}) public User getUser(String name) { User user = userService.selectUserByName(name); return user; } @ApiOperation(value = "通过用户ID查询用户信息", notes = "通过用户ID查询用户信息", produces = "application/json") @ApiImplicitParam(name = "id", value = "用户ID", paramType = "query", required = true, dataType = "int", example="0") @RequestMapping(value = "user/id", method = {RequestMethod.GET, RequestMethod.POST}) public User getUser(Integer id) { User user = userService.selectUserById(id); return user; } @ApiOperation(value = "通过用户年龄查询用户信息", notes = "通过用户年龄查询用户信息", produces = "application/json") @ApiImplicitParam(name = "age", value = "用户年龄", paramType = "query", required = true, dataType = "int", example="0") @RequestMapping(value = "user/age", method = {RequestMethod.GET, RequestMethod.POST}) public List<User> getUserByAge(Integer age) { PageHelper.startPage(1, 2); List<User> users = userService.selectUserByAge(age); return users; } @ApiOperation(value = "新增用户", notes = "新增用户", produces = "application/json") @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "用户名", paramType = "query", required = true, dataType = "String") , @ApiImplicitParam(name = "age", value = "用户年龄", paramType = "query", required = true, dataType = "int", example="0")}) @RequestMapping(value = "user/add", method = RequestMethod.POST) public User addUser(String name, Integer age) { User user = new User(); user.setName(name); user.setAge(age); userService.insertUser(user); return user; } @ApiIgnore @ApiOperation(value = "批量新增用户", notes = "批量新增用户", produces = "application/json") @RequestMapping(value = "user/add/batch", method = RequestMethod.POST) public List<User> addUsers(@RequestBody List<User> users) { userService.batchInsertUser(users); return users; } }
|