数据库

攻略主题表

CREATE TABLE `strategy_theme` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`state` int DEFAULT NULL,
`seq` int DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;

实体类

找到模块:trip-article-api,找到包com.swx.article.domain,创建攻略主题实体类

StrategyTheme
@Getter
@Setter
@TableName("strategy_theme")
public class StrategyTheme {
public static final int STATE_NORMAL = 1;
public static final int STATE_DISABLE = 0;

private Long id;
private String name; // 主题名称
private Integer state = STATE_NORMAL; // 主题状态
private Integer seq; // 主题序号
}

分页查询

接口信息

路径地址 http://localhost:9000/article/strategies/themes/query
请求方式 GET
请求参数 Page
返回结果 Page

Controller

StrategyThemeController
@RestController
@RequestMapping("/strategies/themes")
public class StrategyThemeController {

private final StrategyThemeService strategyThemeService;

public StrategyThemeController(StrategyThemeService strategyThemeService) {
this.strategyThemeService = strategyThemeService;
}

@GetMapping("/query")
public R<Page<StrategyTheme>> pageList(Page<StrategyTheme> page) {
return R.ok(strategyThemeService.page(page));
}
}

查询所有

接口信息

路径地址 http://localhost:9000/article/strategies/themes/list
请求方式 GET
请求参数
返回结果 List

Controller

StrategyThemeController
@GetMapping("/list")
public R<List<StrategyTheme>> listAll() {
return R.ok(strategyThemeService.list());
}

主键查询

接口信息

路径地址 http://localhost:9000/article/strategies/theme/detail
请求方式 GET
请求参数 id
返回结果 StrategyCatalog

Controller

StrategyThemeController
@GetMapping("/detail")
public R<StrategyTheme> getById(Long id) {
return R.ok(strategyThemeService.getById(id));
}

保存攻略主题

接口信息

路径地址 http://localhost:9000/article/strategies/themes/save
请求方式 POST
请求参数 StrategyTheme
返回结果

Controller

StrategyThemeController
@PostMapping("/save")
public R<?> save(StrategyTheme strategyTheme) {
strategyThemeService.save(strategyTheme);
return R.ok();
}

更新攻略主题

接口信息

路径地址 http://localhost:9000/article/strategies/themes/update
请求方式 POST
请求参数 StrategyCatalog
返回结果

Controller

StrategyThemeController
@PostMapping("/update")
public R<?> update(StrategyTheme strategyTheme) {
strategyThemeService.updateById(strategyTheme);
return R.ok();
}

删除攻略分类

接口信息

路径地址 http://localhost:9000/article/strategies/themes/delete/{id}
请求方式 POST
请求参数 id
返回结果

Controller

StrategyThemeController
@PostMapping("/delete/{id}")
public R<?> delete(@PathVariable Long id) {
strategyThemeService.removeById(id);
return R.ok();
}