- 文章链接
- PlayerInfoController
- PlayerInfoService
- PlayerInfoServiceImpl
- PlayerInfoMapper.java
- PlayerInfoMapper.xml
Java多线程实现跑步比赛【比赛详解】
Java多线程实现跑步比赛【基本设计】
Java多线程实现跑步比赛【RunMap——地图映射类】
Java多线程实现跑步比赛【RunMan——运动员映射类】
Java多线程实现跑步比赛【RunManFunc,RunStart,Utils——工具类】
Java多线程实现跑步比赛【SpringBoot——调用逻辑】
package com.sport.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.sport.services.PlayerInfoService; @CrossOrigin(origins = "*", maxAge = 10) @RestController @RequestMapping("/sports") public class PlayerInfoController { @Autowired protected PlayerInfoService playerInfoService; @RequestMapping(path = "/running", method = { RequestMethod.GET }) public void Running(@RequestParam String mapName) { playerInfoService.playerRunning(mapName); } }PlayerInfoService
package com.sport.services; public interface PlayerInfoService { void playerRunning(String mapName); }PlayerInfoServiceImpl
package com.sport.services.impl; import java.util.List; import java.util.UUID; import java.util.concurrent.ThreadPoolExecutor; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.sport.controller.WebSocketServer; import com.sport.entity.PlayerInfoEntity; import com.sport.entity.RunMan; import com.sport.map.RunMap; import com.sport.mapper.PlayerInfoMapper; import com.sport.services.PlayerInfoService; import com.sport.services.RunStart; import com.sport.utils.CsvUtils; import com.sport.utils.MapUtils; import com.sport.utils.ThreadPoolUtils; @Service public class PlayerInfoServiceImpl implements PlayerInfoService { @Autowired protected PlayerInfoMapper playerInfoMapper; @Override public void playerRunning(String mapName) { String uuid = UUID.randomUUID().toString(); ListPlayerInfoMapper.javarunMans = playerInfoMapper.playerQueryAll(); ThreadPoolExecutor threadPoolExecutor = ThreadPoolUtils.buildRunGameThreadPoolExecutor(); RunMap runMap = MapUtils.initRunMap(mapName); for (int i = 0; i < runMans.size(); i++) { threadPoolExecutor.execute(new RunStart(runMap, runMans.get(i), playerInfoMapper, uuid)); } } }
package com.sport.mapper; import java.util.List; import org.apache.ibatis.annotations.Mapper; import org.springframework.stereotype.Repository; import com.sport.entity.GameResult; import com.sport.entity.RunMan; @Mapper @Repository public interface PlayerInfoMapper { public ListPlayerInfoMapper.xmlplayerQueryAll(); public void addGameResult(GameResult gameResult); }
SELECT ID, NAME, AGE, GENDER, AVERAGESPEED, ADDEDWEIGHT FROM PLAYER_INFO INSERT INTO GAME_RESULT(PLAYERID, GAMEID, DATEOFGAME,GAMEMAPNAME,LEAGUE,AVERAGESPEED,GAMEDURATION,GAMECOMMENTARY) VALUES(#{playerId},#{gameId},#{dateOfGame},#{gameMapName},#{league},#{averageSpeed},#{gameDuration},#{gameCommentary})
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)