diff --git a/src/main/java/com/lh/controller/VoteController.java b/src/main/java/com/lh/controller/VoteController.java index 0da9a16..305446f 100644 --- a/src/main/java/com/lh/controller/VoteController.java +++ b/src/main/java/com/lh/controller/VoteController.java @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.io.IOException; +import java.net.URLEncoder; @CrossOrigin @RestController @@ -16,9 +17,10 @@ public class VoteController { private VoteService voteService; //投票. - @PostMapping("/vote/{candidateJwcode}") - public RespBean vote(@PathVariable("candidateJwcode") String candidateJwcode,@RequestBody String token) throws Exception { - token = "token=" + token.substring(0, token.length() - 1); + @PostMapping("/vote") + public RespBean vote(@RequestParam("code") String candidateJwcode, @RequestParam("token") String token) throws Exception { + token = "token=" + URLEncoder.encode(token,"UTF-8"); + System.out.println(token); Utils utils = new Utils(); String voterJwcode = String.valueOf(utils.getJwcode(token)); String voterName = utils.getUsername(token); @@ -32,7 +34,8 @@ public class VoteController { ////将token的值分离出来 //int startIndex = token.indexOf('=') + 1; // 找到等号的位置,并移动到等号后一位 //String tokenValue = token.substring(startIndex); // 提取等号后面的部分 - token = token.substring(10, token.length() - 2); + token = "token=" + URLEncoder.encode(token.substring(10, token.length() - 2), "UTF-8"); + System.out.println(token); String voterJwcode = String.valueOf(new Utils().getJwcode(token)); return RespBean.ok("获取成功",voteService.getCandidates(voterJwcode));