小知识点(问题解决)

1.将service,mapper层抽取出一个基础service、mapper层

步骤:

之前抽取了Query和Domain为BaseQuery 和BaseDomain
步骤:
1.先抽取Mapper接口为BaseMapper(将方法中的实体类型替换成泛型),类上也需要加泛型
interface BaseMapper<T> {
List<T> findAll();
}

 Long queryCount(BaseQuery baseQuery);--BaseQuery--是抽取后的
    List<T> queryData(BaseQuery baseQuery);
2.抽取service接口为IBaseService,和抽取Mapper相同
3.抽取实现类要继承抽取后的接口,
并且依赖注入抽取后的BaseMapper接口
class BaseServiceImpl<T> implements IBaseService<T>


 @Autowired
    private BaseMapper<T> baseMapper;


@Override
    public PageList<T> query(BaseQuery baseQuery) {

实现:
service接口继承IBaseService接口;
extends IBaseService<Employee> {

mapper接口继承BaseMapper接口;
e EmployeeMapper extends BaseMapper<Employee> {

将重复的方法删除
service实现类要继承BaseServiceImpl业务类
 EmployeeServiceImpl extends BaseServiceImpl<Employee>

1.纯前端项目需要在每个功能模块页面引入相应的插件


比如:vue axios common.js(这里是配置好axios的全局属性和基础路径的)
<!--引入vue-->
    <script src="js/vue.js"></script>

<!--    在线引入axios 这里是之前在minio做的-->
    <script src="http://115.159.88.63:9090/resources/axios/dist/axios.min.js"></script>

<!--    引入common.js,里面有axios的全局配置和基础属性-->
    <script src="js/common.js"></script>

无状态的token方案:

1.总体思路:
    前端发请求传递参数
    后端接受参数,处理请求,响应数据
    前端对响应的数据做处理
2.代码实现
    前端发请求传递参数:
      this.logining = true;//显示加载框
      this.$http.post("/login/account",this.ruleForm).then(res=>{
        if(res.data.success){//登录成功
          //将token和logininfo放在localStorage
          localStorage.setItem("token",res.data.resultObj.token); //后续获取redis的登录信息校验登录
          localStorage.setItem("username",res.data.resultObj.logininfo.username);//登录后显示用户信息
          //跳转到后台首页
          this.$router.push({path: '/echarts'});
        }else{
          this.$message.error(res.data.message);
        }
      }).catch(res=>{
        this.$message.error("系统繁忙,请稍后重试");
      })
      this.logining = false;
    后端接受参数,处理请求,响应数据
        dto - controller - service业务
        //一:校验空值
        if(StrUtil.isBlank(loginDto.getAccount()) || StrUtil.isBlank(loginDto.getPassword())){
            throw new BusinessException("信息不能为空");
        }
        //二:校验用户名
        Logininfo logininfo = logininfoMapper.findByAccount(loginDto);
        if(logininfo==null){
            throw new BusinessException("账号不存在");
        }else{
            //三:校验密码
            String dbPwd = logininfo.getPassword();//加密加盐
            String md5Pwd = SecureUtil.md5(loginDto.getPassword() + logininfo.getSalt());
            if(!dbPwd.equals(md5Pwd)){
                throw new BusinessException("密码错误");
            }
        }

        //四:校验是否禁用
        if(!logininfo.getDisable()){
            throw new BusinessException("账号异常,请联系管理员");
        }

        String token = UUID.randomUUID().toString();
        //String token = StrUtils.getComplexRandomString(36);
        //String token = RandomUtil.randomString(36);
        redisTemplate.opsForValue().set(token,logininfo,30, TimeUnit.MINUTES);
        //这里为啥要用map?装多个数据
        Map<String,Object> map = new HashMap<>();
        map.put("token",token);
        logininfo.setSalt(null);
        logininfo.setPassword(null);
        map.put("logininfo",logininfo);
        //五:返回数据
        return AjaxResult.me().setResultObj(map);
    xml中:
        select * from t_logininfo where type=#{type}
                and (username = #{account}
                or phone = #{account}
                or email = #{account})

//获取request请求对象


RequestContext currentContext = RequestContext.getCurrentContext();
HttpServletRequest request = currentContext.getRequest();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值