踩坑记录
-
- 待解决:
-
- vue 前后端分离:
-
- 1】跨域请求跳转
- 1】 2022/2/22更:以下代码使用axios,跨域访问。
- SpringBoot:
-
- 1】模块相互依赖
- 2】使用@Autowired 与 new
- 已解决:
-
- mybatis(plus):
-
- 1】 报错问题:找不到 *Mapper.xml 进行绑定
- spring boot:
-
- 1】 2022/2/10更:spring boot 未扫描到 bean
- vue:
-
- 1】2022/2/22更:error 'options' is defined but never used no-unused-vars 报错解决:
- 回调函数:
待解决:
vue 前后端分离:
1】跨域请求跳转
axios发送请求,使用代理请求到后端之后,接收到了后端的响应,前端应该怎么跳转到请求的界面?
F5之后,地址栏发生变化,界面也会发生变化。显然不是期望的结果,可能对问题描述有点问题。
1】 2022/2/22更:以下代码使用axios,跨域访问。
当前端访问链接:http:localhost:8080/home 想获取到后端数据,需要进行以下配置
pathRewrite:作用是将链接中的 home ,变为 http:localhost:8080/s3,此时实际访问的数据链接为 http://localhost:9191/s3
// vue.config.js
module.exports = {
publicPath: "/",
devServer: {
proxy: {
'/home': {
target: 'http://localhost:9191',
changeOrigin: true,
pathRewrite: {
"^/home": '/s3'
},
},
}
},
}
SpringBoot:
1】模块相互依赖
多模块之间首先不能互相依赖:A模块依赖B模块,B模块依赖A模块。
多模块下,只有一个启动类模块的情况下,另一个模块需要使用启动类模块中的application.yml配置等,却无法使用。
2】使用@Autowired 与 new
使用
@Autowired
注解
UserService userService;
直接调用mybatis-plus内置 list()
userService.list();
方法不会报错。
@Autowired
UserService userService;
public void method() {
List<User> list = userService.list();
list.forEach(System.out::println);
}
不使用
@Autowired
注解,报错,空指针异常。这是为什么?有没有除
@Autowired
和配置
bean.xml
以外的解决办法
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
错误行:List user = service.list();
public void method() {
UserService service = new UserServiceImpl();
List<User> user = service.list();
user.forEach(System.out::println);
}
已解决:
mybatis(plus):
1】 报错问题:找不到 *Mapper.xml 进行绑定
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.xxx.web.mapping.UserMapper.selectttAll
我的 *Mapper.xml 路径在com/xxx/web/mapping/mapper
- 解决
- 将 mapper.xml 文件,放在 resources 下的 mapper 包下
-
yml 配置
mybatis-plus:
mapper-locations: classpath*:《权路径com/xxx/web/mapper/mapping》/*.xml
注意点:在classpath后面的 * 必不可少,缺少型号的话后面的通配符不起作用。
**表示可以表示任意多级目录。
spring boot:
1】 2022/2/10更:spring boot 未扫描到 bean
从〇开始创建 spring boot 项目过程中:
- 1 创建 maven 工程
- 2 导入spring boot 所需的依赖
- 3 能成功启动 spring boot 项目后,添加 mybatis-plus 依赖,配置好数据库参数等;使用 mybatis-plus 下方法,始终报以下错误。
- 道理都懂,com.xxx.web.service.UserService 找不到,考虑缺少 bean。
Description:
Field UserService in com.xxx.web.controller.LoginController required a bean of type ->
-> 'com.xxx.web.service.UserService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.xxx.web.service.UserService' in your configuration.
- 解决
就是没有添加
注解,没有将 com.xxx.web.service.UserService 注入为 bean,导致 spring boot 找不到,所以创建 spring boot项目,首先就该把对应的注解添加上去@Component
vue:
1】2022/2/22更:error ‘options’ is defined but never used no-unused-vars 报错解决:
// package.json
"rules": {
"generator-star-spacing": "off",
"no-tabs": "off",
"no-unused-vars": "off",
"no-console": "off",
"no-irregular-whitespace": "off",
"no-debugger": "off"
}
回调函数:
回调函数是一个函数类型的参数。
使用:
- 由 main 方法,调用 method 方法。
- method 方法体中,调用 callback( params ) 的位置,就是什么时候执行 function 函数方法体执行的位置。
- callback 是一个函数,在 method 中,当作一个参数。
- 还有什么可以补充的…
public void main(){
···main 方法体···
// 调用 method 方法
method (param1, param2, function(params) {
···method 回调函数 function 函数参数的方法体···
});
}
public void method (param1,param2,callback) {
···method 方法体···
callback(params);
}