1.异常错误:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.c
使用了最新的mysql驱动包,但驱动声明不是最新的,将配置文件中的DriverClassName 从 "com.mysql.jdbc.Driver" 换成 "com.mysql.cj.jdbc.Driver"
2. 可以访问静态资源但无法访问html页面
添加thymeleaf依赖
<!--thymeleaf模板引擎-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
3.页面能正常显示css样式,跳转一次后不能
css引用链接为 / 开头
4.thymeleaf的th:href中使用了@{}地址标记后无法通过ctrl点到controller层,但能正常使用
<a class="btn btn-sm btn-danger" th:href="@{/deleteEmp/}+${emp.getId()}">删除</a>
5.前端传到后台的birth字段报错,无法从String转换成Date类型
在pojo类中添加注解
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birth;
6.将Mybatis注解改为XML文件后运行一直报错
未在application.yml中添加配置信息
mybatis:
type-aliases-package: test.demo.pojo
mapper-locations: mapper/DepartmentMapper.xml,mapper/UserMapper.xml
忘记将原来的注解@Select注释掉
xml文件中输入输出类型使用错误,没有使用全限定名
改造成springboot+vue+shiro+swagger
1.前端获得了后端的数据但无法渲染
字段名没有对应
2.修改了查询方法,前端无法显示
Page<Employee> page1 = employeeMapper.selectPage(new Page<>(pageNum, pageSize)
, Wrappers.<Employee>lambdaQuery().like(Employee::getName, search));
//原来的查询
//分页插件
//PageHelper.startPage(pageNum, pageSize);
//List<Employee> page = employeeMapper.selectList(null);
返回的数据存放位置不一样,之前的是在data里面,现在在data.records内
//vue
this.tableData = res.data.records
this.total = res.data.total
3.前台登录数据发送不到后台
报错信息:Uncaught TypeError: Cannot read properties of undefined (reading 'get')
原因:request包引用错误
4.shiro权限认证时报错
报错信息 Uncaught (in promise) Error: Request failed with status code 405
原因:权限认证包括增(post)删(delete)改(put),用@RequestMapping注解
@ApiOperation("未授权返回信息")
@RequestMapping("/unauth")
public Result unauth(){
System.out.println("未授权返回信息");
return new Result(-401,"未授权");
}
5.shiro给权限失败,全部被拦截
不要用==,用equals...
if(principal.getPerms().equals("*") || principal.getPerms().equals("管理员")){
//所有权限
info.addStringPermission("employee:update");
info.addStringPermission("employee:save");
info.addStringPermission("employee:delete");
}else {}
principal.getPerms().equals("管理员")
//返回true
principal.getPerms()=="管理员"
//返回false
(这里为什么会这样?)
测试一下,这样写是打印的两个true
@Test
void contextLoads() {
User user=new User("天天","123","天下",null);
System.out.println(user.getUsername().equals("天天"));
System.out.println(user.getUsername()=="天天");
}
看一下被重写的equals方法,都是相同的
先直接比较地址,相同就返回true,然后coder值相同就依次比较value值
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
String aString = (String)anObject;
if (!COMPACT_STRINGS || this.coder == aString.coder) {
return StringLatin1.equals(value, aString.value);
}
}
return false;
}
//StringLatin1.equals
@HotSpotIntrinsicCandidate
public static boolean equals(byte[] value, byte[] other) {
if (value.length == other.length) {
for (int i = 0; i < value.length; i++) {
if (value[i] != other[i]) {
return false;
}
}
return true;
}
return false;
}
-
从 Java9 版本开始,将 char[] 字段改为了 byte[] 字段,又维护了一个新的属性 coder,它是一个编码格式的标识。
6. 使用PageHelper回传的数据条数只有当前页
将查询出来的List<>放入PageInfo内
PageHelper.startPage(pageNum, pageSize);
List<Orders> page = ordersMapper.queryOrders(search);
PageInfo<Orders> pageInfo = new PageInfo<Orders>(page);
return pageInfo;
7.BigDecimal和Int类型不能直接运算
把Int类型的num转成BigDecimal类型后相乘
BigDecimal total = new BigDecimal(num).multiply(goods.getPrice());
add(BigDecimal)BigDecimal对象中的值相加,然后返回这个对象。
subtract(BigDecimal)BigDecimal对象中的值相减,然后返回这个对象。
multiply(BigDecimal)BigDecimal对象中的值相乘,然后返回这个对象。
divide(BigDecimal)BigDecimal对象中的值相除,然后返回这个对象。
8.Mapper.xml从传入的实体类参数中取值
用$而不是#
insert orders values (null,${emp.getId()},${goods.getId()},${quantity},${total},${buyTime})
9.java向数据库中插入DateTime类型的数据
用Timestamp类型,传入Date类型参数
new Timestamp(new Date().getTime())
<insert id="insertOrders" parameterType="com.demo.demo.pojo.Orders">
insert orders values(null
,${emp.getId()}
,${goods.getId()}
,${quantity}
,${total}
,'${buyTime}')
</insert>
//时间类型一定要带单引号 ''
@Test
void contextLoads() throws ParseException {
Orders orders = new Orders(99, 1, new BigDecimal(22),
new Timestamp(new Date().getTime()), new Goods(3), new Employee(2));
ordersMapper.insertOrders(orders);
}
10.从数据库中读出来显示到前端的时间少了8个小时,数据库内存储正常
springboot中对加了@RestController或者@Controller+@ResponseBody注解的方法的返回值默认是Json格式,
所以,对date类型的数据,在返回浏览器端时,会被springboot默认的Jackson框架转换,而Jackson框架默认的时区GMT(相对于中国是少了8小时)。所以最终返回到前端结果是相差8小时
————————————————
版权声明:本文为CSDN博主「穿越23小时」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_42031483/article/details/100625564
配置文件中加入
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8