|
9 | 9 | @RestController
|
10 | 10 | public class SessionController {
|
11 | 11 |
|
12 |
| - // http://127.0.0.1:8080/session/login?username=xinping&password=123 |
13 |
| - // http://127.0.0.1:8081/session/login?username=xinping&password=123 |
| 12 | + /** |
| 13 | + * 登录系统 |
| 14 | + * |
| 15 | + * http://127.0.0.1:8080/session/login?username=xinping&password=123 |
| 16 | + * http://127.0.0.1:8081/session/login?username=xinping&password=123 |
| 17 | + * */ |
14 | 18 | @RequestMapping(value="/session/login", method = RequestMethod.GET)
|
15 | 19 | @ResponseBody
|
16 | 20 | public Map login(@RequestParam("username") String username,@RequestParam("password") String password,HttpServletRequest request, HttpSession session) {
|
17 |
| - System.out.println("===============登录成功==============="); |
18 |
| - User user = new User(); |
19 |
| - user.setName(username); |
20 |
| - user.setPassword(password); |
21 |
| - request.getSession().setAttribute("admin", user); |
22 |
| - String sessionId = session.getId(); |
23 |
| - System.out.println("sessionId="+sessionId); |
24 |
| - Map result = new HashMap(); |
25 |
| - result.put("message" , user); |
26 |
| - result.put("sessionId",sessionId); |
| 21 | + String message = "login failure"; |
| 22 | + Map<String, Object> result = new HashMap<String, Object>(); |
| 23 | + if(username != null && "xinping".equals(username) && "123".equals(password)){ |
| 24 | + User user = new User(); |
| 25 | + user.setName(username); |
| 26 | + user.setPassword(password); |
| 27 | + request.getSession().setAttribute("admin", user); |
| 28 | + message = "login success"; |
| 29 | + result.put("message" , message); |
| 30 | + result.put("sessionId",session.getId()); |
| 31 | + }else{ |
| 32 | + result.put("message" , message); |
| 33 | + } |
| 34 | + |
27 | 35 | return result;
|
28 | 36 | }
|
29 | 37 |
|
30 |
| - // http://127.0.0.1:8080/session/get?username=xinping |
31 |
| - // http://127.0.0.1:8082/session/get?username=xinping |
| 38 | + /** |
| 39 | + * 查询用户 |
| 40 | + * |
| 41 | + * http://127.0.0.1:8080/session/get?username=xinping |
| 42 | + * http://127.0.0.1:8082/session/get?username=xinping |
| 43 | + * */ |
32 | 44 | @RequestMapping(value="/session/get", method = RequestMethod.GET)
|
33 | 45 | @ResponseBody
|
34 | 46 | public Map get(@RequestParam("username") String username,HttpServletRequest request, HttpSession session) {
|
35 |
| - System.out.println("=============== 查询用户信息 ==============="); |
36 | 47 | Object value = request.getSession().getAttribute("admin");
|
37 |
| - Map result = new HashMap(); |
38 |
| - String sessionId = session.getId(); |
| 48 | + Map<String,Object> result = new HashMap<String,Object>(); |
39 | 49 | result.put("message" ,value);
|
40 |
| - result.put("sessionId",sessionId); |
| 50 | + result.put("sessionId",session.getId()); |
41 | 51 | return result;
|
42 | 52 | }
|
43 | 53 |
|
44 |
| - // http://127.0.0.1:8080/session/logout |
45 |
| - @RequestMapping(value = "logout", method = RequestMethod.GET) |
| 54 | + /** |
| 55 | + * 退出系统 |
| 56 | + * |
| 57 | + * http://127.0.0.1:8080/session/logout |
| 58 | + * http://127.0.0.1:8081/session/logout |
| 59 | + * */ |
| 60 | + @RequestMapping(value = "/session/logout", method = RequestMethod.GET) |
46 | 61 | @ResponseBody
|
47 | 62 | public Map logout(HttpSession session) {
|
48 |
| - System.out.println("============退出系统============="); |
49 |
| - System.out.println(session.getId()); |
50 | 63 | session.removeAttribute("admin");
|
51 | 64 | session.invalidate();
|
52 | 65 | Map result = new HashMap();
|
|
0 commit comments