踩坑記錄
-
- 待解決:
-
- 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);
}