学习流程-2024-07
学习流程-2024-07-20
1.cordova项目添加android平台后,用android studio打开platforms/android,“在模拟器运行”按钮为灰色不可点。需要点右上角sync project with gradle files。但点了之后报错如下,下一步解决该问题:
Download https://services.gradle.org/distributions/gradle-6.8-bin.zip finished, took 8 m 20 s 611 ms (107.84 MB) Starting Gradle Daemon... Gradle Daemon started in 3 s 762 ms FAILURE: Build failed with an exception. * Where: Script 'D:\study\cordova\project\myApp\platforms\android\CordovaLib\cordova.gradle' line: 79 * What went wrong: A problem occurred evaluating script. > No usable Android build tools found. Highest 34.x installed version is 33.0.2; Recommended version is 34.0.0. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 13s
学习流程2024-07-21
1.卸载Android studio 3.5.2,安装Android studio 2024.1.1。用2024.1.1打开项目仍有报错,正在排查,后面确定一下2024.1.1的sdk要配成和电脑中已有的2021.1.1一样的sdk吗?
学习流程2024-07-23
1.练习前后端传参
后端BookApiController.java:
/** * 一开始我的是错误的:@RestController("/api/bookApiController") * * 分析:"/api/bookApiController"这种一定是@RequestMapping注解后面的 */ @RestController @RequestMapping("/api/bookApiController") public class BookApiController { /** * 练习前后端传参,无具体service层代码 * * 我一开始的错误写法:@RequestMapping(value = "deleteBookById", method = RequestMethod.DELETE) * 会报404 * * 且一开始没加@ResponseBody,报404,初步分析是在目前这框架中,@RestController不能达到替换@Controller+@ResponseBody的效果? * @param id * @return */ @RequestMapping(value = "deleteBookById/{id}", method = RequestMethod.DELETE) @ResponseBody public PracticeAjaxJson deleteBookById(@PathVariable("id") String id) { PracticeAjaxJson j = new PracticeAjaxJson(); j.setMsg("删除成功"); try { System.out.println("id from frontEnd: " + id); j.setSuccess(true); } catch (Exception e) { j.setSuccess(false); j.setMsg(e.getMessage()); } return j; } /** * 练习前后端传参,无具体service层代码 * @param id * @return */ @RequestMapping(value = "deleteBookByIdWithError/{id}", method = RequestMethod.DELETE) @ResponseBody public PracticeAjaxJson deleteBookByIdWithError(@PathVariable("id") String id) { PracticeAjaxJson j = new PracticeAjaxJson(); j.setMsg("删除成功"); try { System.out.println("id from frontEnd: " + id); int number = 0; int result = 2 / number; j.setSuccess(true); } catch (Exception e) { j.setSuccess(false); j.setMsg(e.getMessage()); } return j; } }
用于响应前端的PracticeAjaxJson.java:
public class PracticeAjaxJson { private boolean success; private String msg = "操作成功"; public boolean isSuccess() { return success; } public void setSuccess(boolean success) { this.success = success; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } }
前端:
<template> <f7-page> <button @click="practiceDeleteBook()">验证前后端传参(正常请求)</button> <button @click="practiceDeleteBookWithError()">验证前后端传参(模拟后端报错)</button> </f7-page> </template> <script> export default { methods: { practiceDeleteBook() { const _self = this; const id = 'bookId0723'; _self.request.delete({ url: '/bookApiController/deleteBookById/' + id }).then(function(response) { if (response.data.success) { messagef7(response.data.msg); } }).catch((error) => { console.log(error); }) }, /** * 没按我期望的进入.catch((error) => {})里,下一步确认。 */ practiceDeleteBookWithError() { const _self = this; const id = 'bookId0723'; _self.request.delete({ url: '/bookApiController/deleteBookByIdWithError/' + id }).then((response) => { debugger if (response.data.success) { messagef7(response.data.msg); } }).catch((error) => { debugger console.log(error); }) } } </script>