梅开三度
开发流程
该业务基于rouyi生成好了mapper和service的代码,现在需要在controller层写接口
实际操作流程:
看接口文档一>controller里定义函数一>看给出的工具类一>补全controller里的函数一>运行测试
接口文档
在用户模块用户先看到活动列表,在活动列表内点击具体活动,进入看到活动信息、奖品信息和中奖列表。
controller里定义
在注解框架里加上list、info、products和hit四个函数
@RestController
@RequestMapping(value = "/api/game")
@Api(tags = {"活动模块"})
public class GameController {
@Autowired
private GameLoadService loadService;
@Autowired
private CardGameService gameService;
@Autowired
private ViewCardUserHitService hitService;
@GetMapping("/list/{status}/{curpage}/{limit}")
@ApiOperation(value = "活动列表")
@ApiImplicitParams({
@ApiImplicitParam(name="status",value = "活动状态(-1=全部,0=未开始,1=进行中,2=已结束)",example = "-1",required = true),
@ApiImplicitParam(name = "curpage",value = "第几页",defaultValue = "1",dataType = "int", example = "1",required = true),
@ApiImplicitParam(name = "limit",value = "每页条数",defaultValue = "10",dataType = "int",example = "3",required = true)
})
public ApiResult list(@PathVariable int status,@PathVariable int curpage,@PathVariable int limit) {
//TODO
return null;
}
@GetMapping("/info/{gameid}")
@ApiOperation(value = "活动信息")
@ApiImplicitParams({
@ApiImplicitParam(name="gameid",value = "活动id",example = "1",required = true)
})
public ApiResult<CardGame> info(@PathVariable int gameid) {
//TODO
return null;
}
@GetMapping("/products/{gameid}")
@ApiOperation(value = "奖品信息")
@ApiImplicitParams({
@ApiImplicitParam(name="gameid",value = "活动id",example = "1",required = true)
})
public ApiResult<List<CardProductDto>> products(@PathVariable int gameid) {
//TODO
return null;
}
@GetMapping("/hit/{gameid}/{curpage}/{limit}")
@ApiOperation(value = "中奖列表")
@ApiImplicitParams({
@ApiImplicitParam(name="gameid",value = "活动id",dataType = "int",example = "1",required = true),
@ApiImplicitParam(name = "curpage",value = "第几页",defaultValue = "1",dataType = "int", example = "1",required = true),
@ApiImplicitParam(name = "limit",value = "每页条数",defaultValue = "10",dataType = "int",example = "3",required = true)
})
public ApiResult<PageBean<ViewCardUserHit>> hit(@PathVariable int gameid,@PathVariable int curpage,@PathVariable int limit) {
//TODO
return null;
}
}
看给出的工具类
找该模块附近的common和util包
补全controller里的函数
基本就用wrapper查下
@RestController
@RequestMapping(value = "/api/game")
@Api(tags = {"活动模块"})
public class GameController {
@Autowired
private GameLoadService loadService;
@Autowired
private CardGameService gameService;
@Autowired
private ViewCardUserHitService hitService;
@GetMapping("/list/{status}/{curpage}/{limit}")
@ApiOperation(value = "活动列表")
@ApiImplicitParams({
@ApiImplicitParam(name="status",value = "活动状态(-1=全部,0=未开始,1=进行中,2=已结束)",example = "-1",required = true),
@ApiImplicitParam(name = "curpage",value = "第几页",defaultValue = "1",dataType = "int", example = "1",required = true),
@ApiImplicitParam(name = "limit",value = "每页条数",defaultValue = "10",dataType = "int",example = "3",required = true)
})
public ApiResult list(@PathVariable int status,@PathVariable int curpage,@PathVariable int limit) {
QueryWrapper<CardGame> wrapper = new QueryWrapper<>();
if (status != -1) {
wrapper.eq("status",status);
}
Page<CardGame> all = gameService.page(new Page(curpage,limit),wrapper);
return new ApiResult(1,"成功",new PageBean<CardGame>(all));
}
@GetMapping("/info/{gameid}")
@ApiOperation(value = "活动信息")
@ApiImplicitParams({
@ApiImplicitParam(name="gameid",value = "活动id",example = "1",required = true)
})
public ApiResult<CardGame> info(@PathVariable int gameid) {
CardGame game = gameService.getById(gameid);
return new ApiResult(1,"成功",game);
}
@GetMapping("/products/{gameid}")
@ApiOperation(value = "奖品信息")
@ApiImplicitParams({
@ApiImplicitParam(name="gameid",value = "活动id",example = "1",required = true)
})
public ApiResult<List<CardProductDto>> products(@PathVariable int gameid) {
List<CardProductDto> productList = loadService.getByGameId(gameid);
return new ApiResult(1,"成功",productList);
}
@GetMapping("/hit/{gameid}/{curpage}/{limit}")
@ApiOperation(value = "中奖列表")
@ApiImplicitParams({
@ApiImplicitParam(name="gameid",value = "活动id",dataType = "int",example = "1",required = true),
@ApiImplicitParam(name = "curpage",value = "第几页",defaultValue = "1",dataType = "int", example = "1",required = true),
@ApiImplicitParam(name = "limit",value = "每页条数",defaultValue = "10",dataType = "int",example = "3",required = true)
})
public ApiResult<PageBean<ViewCardUserHit>> hit(@PathVariable int gameid,@PathVariable int curpage,@PathVariable int limit) {
QueryWrapper<ViewCardUserHit> wrapper = new QueryWrapper<>();
if (gameid == -1) {
wrapper.eq("gameid",gameid);
}
Page<ViewCardUserHit> all = hitService.page(new Page(curpage,limit),wrapper);
return new ApiResult(1,"成功",new PageBean<ViewCardUserHit>(all));
}
}
运行测试
前后端联调: