这里记录项目中的注意事项以及一些小技巧,还有一些踩过的小坑.
1. controller中获取token的方式
a) 在客户端从vuex中获取token,写在参数里,接收的DTO多写一个token属性
b) 如果是page方法,使用map接收,用项目中的MyQuery封装类构造QueryWrapper,则不能使用a方法,MyQuery封装类已经屏蔽了构建wrapper时对一些关键词的构建,可以自己添加,如果没屏蔽token,则构建wrapper时会将token也作为查询条件执行sql语句.
c) 在服务器端获取请求request
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
推荐使用: 如果是单表查询,推荐使用第一种.
如果是多表查询,则在使用封装的构造器基础上,推荐使用第二种,
如果该关键字有可能是数据库字段,不能进行屏蔽,则使用其他方式
2. 切面中获取token
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
使用request获取cookie中的token
3. 在前端中<el-input type=”number” />时,用户往往可以输入一些非法数字,扰乱系统
<el-input
v-model="formAdd.fciCustomerInfoAge"
οninput="if(value.length > 3) value=value.slice(0, 3)"
οnkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)));"
type="number"
placeholder="年龄"
/>
以上代码,有限制只能输入数字,也有最多输入的长度
4. 在前台向后台传输时间时候,可能遇到无法解析,并且报错
Cannot parse date "2022-06-21 15:15:00": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX'
可以在该字段加注解
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
5. 事务的使用
在ServicesImpl的方法上注解@Transactional
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//手动触发事务回滚
6. Table中判断单元格的变动
<template slot-scope="scope">
<span v-if="scope.row.status === 0">停用</span>
<template slot-scope="scope">
<span v-if="scope.row.status === 0">停用</span>
<span v-if="scope.row.status === 1">启用</span>
</template>