我应该如何以及在何处在以下rest控制器中创建http会话作为Cookie表单?

lymnna71  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(167)

下面给出了我在登录时访问模型的代码。我还想创建一个会话变量,该变量应该由控制器返回,用于进一步的访问机制。我尝试使用@cookievalue注解创建,但无法处理post请求。请帮忙。
控制器正在返回一个模型作为响应。我想创建并发送带有响应的cookie。

@RestController
@PostMapping("/login")
    public DModel abcLogin(@RequestParam("logid") String logid, @RequestParam("logpass") String logpass, @RequestParam("logrole") String logrole) {

         return this.loginInterface.getAbcLogin(logid, logpass, logrole);
    }

@Override
    public DModel getAbcLogin(String logid, String logpass, String logrole) {
        if(logid.indexOf('@') != -1) {

            AbcsModels pModel = AbcsDao.findByAbcEmail(logid);

            if(pModel != null) {

                String password = pModel.getAbcPassword();
                if(logpass.equals(password)) {

                    int AbcId = pModel.getAbcId();
                    String AbcName = pModel.getAbcName();
                    String AbcEmail = pModel.getAbcEmail();
                    String AbcMobileNumberFirst = pModel.getAbcMobileNumberFirst();

                    String profilePic = pModel.getAbcProfilePicture();
                    if(profilePic != null) {

                    byte[] resource = this.GetProfilePic(AbcId, profilePic);

                    List<DasboardAbcAppointment> appointmentList = this.appointmentServiceInterface.getAbcByAbcId(AbcId);

                    DModel pdModel = new DModel(AbcId,AbcName, AbcEmail, AbcMobileNumberFirst, appointmentList,resource);

                    return pdModel;

                }else
                {
                    List<DasboardAbcAppointment> appointmentList = this.appointmentServiceInterface.getAbcByAbcId(AbcId);

                    DModel pdModel = new DModel(AbcId,AbcName, AbcEmail, AbcMobileNumberFirst, appointmentList, null);

                    return pdModel;
                }
                }
                else {
                    return null;
                }

            }
            else {
                return null;
            }

            }
        else {
            AbcsModels pModel = AbcsDao.findByAbcMobileNumberFirst(logid);  
            if(pModel != null) {

                    String password = pModel.getAbcPassword();
                    if(logpass.equals(password)) {

                        int AbcId = pModel.getAbcId();
                        String AbcName = pModel.getAbcName();
                        String AbcEmail = pModel.getAbcEmail();
                        String AbcMobileNumberFirst = pModel.getAbcMobileNumberFirst(); 
                        String profilePic = pModel.getAbcProfilePicture();
                        if(profilePic != null) {
                        byte[] resource = this.GetProfilePic(AbcId, profilePic);
                        List<DasboardAbcAppointment> appointmentList1 = this.appointmentServiceInterface.getAbcByAbcId(AbcId);

                        DModel pdModel = new DModel(AbcId,AbcName, AbcEmail,AbcMobileNumberFirst, appointmentList1, resource);

                        return pdModel;

                    }else
                    {
                        List<DasboardAbcAppointment> appointmentList1 = this.appointmentServiceInterface.getAbcByAbcId(AbcId);
                        DModel pdModel = new DModel(AbcId,AbcName, AbcEmail,AbcMobileNumberFirst, appointmentList1, null);
                        return pdModel;
                    }
                    }
                else {
                    return null;
                }

                }
                else {
                    return null;
                }

        }

    }

private byte[] GetProfilePic(int AbcId, String profilePic) {

            String uploads = Abcfolder+AbcId+"/";
            Path filename = Paths.get(uploads, profilePic);
            byte[] byteArrayResource = null;
            try {
                byteArrayResource = Files.readAllBytes(filename);
            } catch (IOException e) {
                e.printStackTrace();
            }

            return byteArrayResource;
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题