//接口定義在Controller層,接口實現在Service層
package com.xolo.core.controller; //包名 import com.xolo.core.entity.Wechat; //實體名 import com.xolo.core.request.WechatRequest; //請求類型 import com.xolo.core.response.Response; //返回值類型 import com.xolo.core.service.WechatService; //service層代碼 import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.List; @Api(tags = "微信號接口") //接口文檔行頭文字 @RestController @RequestMapping("/kpi/wechat") //接口請求地址 public class WechatController { @Autowired //用來給指定的字段或方法注入所需的外部資源 private WechatService wechatService; //每定義一個變量之前都需加一個@Autowired,否則引用變量語句要改為this.redisService @GetMapping("/list") //接口請求地址,請求方式為GET類型 @ApiOperation("獲取用戶下的所有微信號, 若user_id為0, 則獲取全部微信號列表") //接口功能描述 public Response<List<Wechat>> getUserWechat(@RequestParam("pageNum") //請求參數標識,前端可見 @ApiParam("分頁頁碼") //請求參數描述 Integer pageNum, @RequestParam("pageSize") @ApiParam("一頁數據量") Integer pageSize, @RequestParam("user_id") @ApiParam(name = "user_id", value = "用戶id", defaultValue = "1") Integer userId) { return wechatService.getUserWechat(pageNum,pageSize,userId); //接口具體實現代碼放在Service層 } @PostMapping("/add") //請求方式為POST類型 @ApiOperation("添加微信號") public Response<Boolean> createWechat(@RequestBody WechatRequest wechatRequest) { return wechatService.createWechat(wechatRequest); } @PostMapping("/add/qrcode") @ApiOperation("新增或修改微信二維碼") public Response<Boolean> addWechatQrcode(@RequestParam("wechat") @ApiParam("微信號") String wechat, @RequestParam("file") MultipartFile file) throws IOException { //接收前端form-data格式的文件 return wechatService.addWechatQrcode(wechat,file); } @PostMapping("/move/wechat") @ApiOperation("移動微信") public Response<Boolean> moveWechatUser(@RequestParam("wechat") @ApiParam("微信號List") List<String> wechatList, @RequestParam("user_id") @ApiParam("用戶Id") Integer userId, HttpServletRequest request) { //接收token字段,可根據token字段判斷進行當前操作的用戶信息 String token=request.getHeader("Authorization"); return wechatService.moveWechatUser(wechatList,userId,token); } @PostMapping("/modify/wechatName") @ApiOperation("修改微信名稱") public Response<Boolean> updateWechatName(@RequestParam("wechat_id") @ApiParam("微信號Id") Integer wechatId, @RequestParam("wechat") @ApiParam("微信號") String wechat) { return wechatService.updateWechatName(wechatId,wechat); } }
如果覺得上述內容還可以的話,可以掃描下方二維碼進行贊賞喲~👇👇👇
同時也可關注微信公眾號獲得更多個人分享~👇👇👇