<!--集成mysql数据库--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.30</version><!--$NO-MVN-MAN-VER$--> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <!--lombok注解简化代码--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency>
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/mysql?useSSL=false&useUnicode=true&characterEncoding=utf-8 spring.datasource.username=root spring.datasource.password=root
spring.datasource.url=jdbc: mysql: //localhost:3306/mysql?useSSL=false&useUnicode=true&characterEncoding=utf-8
红色标注的是名为 mysql 的数据库,大家不要全部照抄。
@Autowired JdbcTemplate jdbcTemplate; @ResponseBody @RequestMapping("/save") public String save(@RequestBody Map params) throws IOException { // ------定义推送结果-------- String a; // ------获取推送数据-------- id = (String) params.get("id"); //创建任务接口返回的id companyId = (Integer) params.get("companyId"); //公司id templateId = (Integer) params.get("templateId");//模板id templateName = (String) params.get("templateName");//模板名称 phone = (String) params.get("phone"); //外呼号码 result = (String) params.get("result");//外呼结果 callTime = (String) params.get("callTime");//外呼时间 taskId = (String) params.get("taskId");//外呼任务id callDuration = (Integer) params.get("callDuration");//外呼时长 voiceText = (String) params.get("voiceText");//对话信息 intention = (String) params.get("intention");//意向 intentionRoute = (String) params.get("intentionRoute");//意向路径 intentionScore = (Integer) params.get("intentionScore");//意向分数 telnum = (String) params.get("telnum");//外呼主叫号码 callRound = (Integer) params.get("callRound");//呼叫轮次 visitResult = (String) params.get("visitResult");//报表意向回访状态 lastRoundFlag = (Boolean) params.get("lastRoundFlag");//是否最后一轮 totalDuration = (Integer) params.get("totalDuration");//外呼总时长 userData = (Map<String, Object>) params.get("userData");//透传字段 visitResultReport = (Map) params.get("visitResultReport");//报表意向回访结果 sex = (Map<String, Object>) params.get("sex");//性别 dynamicProperties = (Map) params.get("dynamicProperties");//动态字段 hangUpDirect = (String) params.get("hangUpDirect");//挂断方向 fdsfPath = (String) params.get("fdsfPath");//通话录音文件路径 dialogueList = (List) params.get("dialogueList");//人机对话详情 // ************** 存入mysql ********************* // ---------清空表----------- String sql = "DELETE FROM url_table"; jdbcTemplate.update(sql); // --------存入新数据------------ sql = "INSERT INTO url_table(" + "`id`,`companyId`,`templateId`,`templateName`,`phone`," + "`result`,`callTime`,`taskId`,`callDuration`,`voiceText`," + "`intention`,`intentionRoute`,`intentionScore`,`telnum`,`callRound`," + "`visitResult`,`lastRoundFlag`,`totalDuration`,`userData`,`visitResultReport`," + "`sex`,`dynamicProperties`,`hangUpDirect`,`fdsfPath`,`dialogueList`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; jdbcTemplate.update(sql, id, companyId.toString(), templateId.toString(), templateName, phone, result, callTime, taskId, callDuration.toString(), voiceText, intention, intentionRoute, intentionScore.toString(), telnum, callRound.toString(), visitResult, lastRoundFlag.toString(), totalDuration.toString(), userData.toString(), visitResultReport.toString(), sex.toString(), dynamicProperties.toString(), hangUpDirect, fdsfPath, dialogueList.toString() ); //存储数据库成功且必填字段不为空,则推送成功 if (phone != null && result != null && id != null && callRound != null && companyId != null && templateId != null && templateName != null) { a = "推送成功"; } else { a = "推送失败,缺失必填值"; } return a; }