if (cx.equals(“管理员”)) { table = “admins”; Admins user = adminsService.login(username, pwd); if (user == null) { return showError(“用户名或密码错误”); } session.setAttribute(“id”, user.getId()); session.setAttribute(“username”, user.getUsername()); session.setAttribute(“cx”, cx); session.setAttribute(“login”, cx); session.setAttribute(“username”, user.getUsername()); session.setAttribute(“pwd”, user.getPwd()); JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(user)); jsonObject.put(“cx”, session.getAttribute(“cx”)); jsonObject.put(“username”, session.getAttribute(“username”)); jsonObject.put(“login”, session.getAttribute(“login”)); assign(“session”, jsonObject); } 把这段代码转换成伪代码
时间: 2024-03-12 14:48:49 浏览: 48
如果cx等于“管理员”,则执行以下操作:
- 将table赋值为“admins”;
- 调用adminsService的login方法,将username和pwd作为参数传入,将结果赋值给user;
- 如果user为null,则返回showError("用户名或密码错误");
- 将user的id、username、pwd等属性值分别存入session中;
- 将user转换为JSON格式,并将session中的cx、username、login属性值也存入JSON对象中;
- 将JSON对象存入一个名为session的变量中。
伪代码如下:
```
if (cx.equals("管理员")) {
table = "admins";
user = adminsService.login(username, pwd);
if (user == null) {
return showError("用户名或密码错误");
}
session.id = user.id;
session.username = user.username;
session.cx = cx;
session.login = cx;
session.username = user.username;
jsonObject = json(user);
jsonObject.cx = session.cx;
jsonObject.username = session.username;
jsonObject.login = session.login;
session = jsonObject;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)