JavaWeb后期与SpringBoot遇到的坑

JavaWeb

1 无法解析${}的可能原因:

webapp那个版本太低,要进行升级

我的解决办法:

把web.xml的内容换掉, 换之前要记得备份,记得备份,记得备份

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

</web-app>

image-20211229151058798

Vue

1 axios的this陷阱

这里有个坑: 这里的this才是vue的this 在beforeCreated发起会太早

<script>
        let vue = new Vue({
            el: "#app",
            data: {
                list:[]
            },
            created(){
                //这里有个坑: 这里的this才是vue的this     在beforeCreated发起会太早
                let self = this;
                axios.get("http://localhost:8080/users").then(function (response){
                    console.log(response)
                    self.list=response.data.data;
                })
            }
        });
    </script>

2 @click="delete" 是不行的

可能delete是关键字的原因吧

<tr v-for="item in list">
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.time}}</td>
                <td>
<!--                    这里不要写delete-->
                    <button  @click="del(item.id)">删除</button>
                </td>
            </tr>

3 configuration has an unknown property 'plugin'. These properties are valid:

这个错误其实就是少加了个 s

把19行的plugin 改成 plugins 就ok了

image-20220308211251984

4 HtmlWebpackPlugin didn’t return html

解决方案:升级HtmlWebpackPlugin 插件,webpack 5.22.0以上版本对应 html-webpack-plugin 5.3.0 上版本

package.json

{
  "devDependencies": {
    "clean-webpack-plugin": "^4.0.0",
    "css-loader": "^6.7.1",
    "html-webpack-plugin": "^5.5.0",
    "style-loader": "^3.3.1",
    "webpack": "^5.4.0",
    "webpack-cli": "^4.9.1",
    "webpack-dev-server": "^4.6.0"
  },
  "dependencies": {
    "bootstrap3": "^3.3.5",
    "jquery": "^3.6.0"
  }
}

5 在前端 webpack中 修改了 配置,记得重启服务器

若修改了配置,一定要重启服务,一定要重启服务,一定要重启服务

Mybatis的坑

1 Public Key Retrieval is not allowed

我的解决办法:

在url后面加上: allowPublicKeyRetrieval=true (注意与前面的连接符)

2 从数据库获取的时间成了英文,有CST

image-20220305230250993

解决办法

@JsonFormat(pattern = "yyyy-MM-dd")
private Date time;

3 mybatis的mapper配置文件中,在标签中能不加注释就不加注释

今天的项目出的bug真让人心累

一请求就给我报错

{"msg":"nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='markId', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).","code":500}

现在回想起来,真特么无语,当时看了报错信息明明知道是参数问题,但看代码的话,参数又确实没问题(也是当时警觉性不够),在那无语了半小时,

在一顿疯狂重启服务器后,看那注释有点不爽,就把它删了(就下面第99行的代码), 然后就特么神奇的运行起了...... 后面就一直C语言中

image-20220404223026921

下满就总结下原因:

解析的时候会先解析关键字,然后才组装成为sql进行查询

如何避免: 第一种方法是最靠谱的(就是不要去注释,不要就删掉)

第一种方法: 在这种情况下,尽量就写一条 sql语句, 不要写了不用就注释(快捷键注释,ctrl+/),这样的话,有些内容很可能就会被解析为关键字,比如#{ "参数"}

第二种方法:用这个注释 HTML的注释, 这样就不会被解析到,

而 ctrl+/ 这种快捷键的注释 是 两个横岗 -- ,这种注释就不行(不知道Idea这个软件怎么回事,***)

再记录下一个小知识点

当两个数据库表的 主键名字是一样时,可以 采用别名,这时在resultMap要将对应的column 改成别名

image-20220404221831498

image-20220404221907490

posted @ 2022-04-04 22:56  后端小知识  阅读(123)  评论(0编辑  收藏  举报
返回顶端