项目正常启动,代码也没有报错 ,提交验证后出现这个问题。

来源:6-3 后端实现登录RESTful接口,并颁发令牌

qq_北辰元凰_0

2023-12-12

图片描述package com.example.his.api.mis.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.example.his.api.common.R;
import com.example.his.api.mis.controller.form.LoginForm;
import com.example.his.api.mis.service.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mis/user")
public class UserController {
@Resource
private UserService userService;

@PostMapping("/login")
//@Valid 做后端验证 根据 LoginForm 中的验证注解验证变量内容
public R login(@RequestBody @Valid LoginForm form) {
    //把Form对象转换成Map对象。因为Form对象中含有后端验证表达式,该对象仅用于Web层,不适合传给业务层
        Map param = BeanUtil.beanToMap(form);

    //获取登陆用户的主键值
    Integer userId = userService.login(param);
    System.out.println(userId);
    if (userId != null) {
        /*
         * 实现同端互斥效果,把该用户Web端的令牌销毁。
         * 在其他浏览器上已经登陆的该账户,令牌就失效了,实现同端互斥。
         */
        StpUtil.logout(userId,"Web");

        //通过会话对象,向SaToken传递userId
        StpUtil.login(userId,"Web");
        //生成新的令牌字符串,标记该令牌是给Web端用户使用的
        String token = StpUtil.getTokenValueByLoginId(userId, "Web");
        //获取用户的权限列表
        List<String> permissions = StpUtil.getPermissionList();
        //向前端返回数据
        return R.ok().put("result", true).put("token", token).put("permissions", permissions);
    }
    //如果登陆失败,返回给前端的result是false
    return R.ok().put("result", false);
}

}

写回答

1回答

神思者

2023-12-12

应该是你配置的restkit插件不对
1
7
慕仔6336206
回复
qq_北辰元凰_0
回复 qq_北辰元凰_0:这个错误是没有注解扫描不到
2024-11-12
共7条回复

SpringBoot+Vue3+MySQL集群 开发大健康体检双系统

SpirngBoot+Vue3+ MySQL集群 开发大健康体检双系统

318 学习 · 213 问题

查看课程