后端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.jhj.gulimall.auth.server.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@Controller
public class LoginController {


@GetMapping("/login")
public void loginPage(HttpSession session){

HashMap<Object, Object> map = new HashMap<>();
map.put("userName","aaa");
map.put("password","123456");
session.setAttribute("user",map);
}

@PostMapping("/login2")
public void loginPage2(HttpSession session){

HashMap<Object, Object> map = new HashMap<>();
map.put("userName","aaa2");
map.put("password","123456");
session.setAttribute("user",map);
}

@PostMapping("/reg")
public void regPage(HttpSession session){

System.out.println(session.getAttribute("user"));
}
}

前端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
login(){

axios({

method: "post",
url: `http://localhost:20000/login2`,
//携带cookie
withCredentials:true
// data: {

// file:id
// },
// //自定义header
// headers: {

// // 'content-type': 'application/json;charset=UTF-8'
// // "Content-Type": "application/x-www-form-urlencoded",
// "content-type":"multipart/form-data"
// },
}).then(function (res) {

console.log(res);
});
},
reg(){

axios({

method: "post",
url: `http://localhost:20000/reg`,
//携带cookie
withCredentials:true
// data: {

// file:id
// },
// //自定义header
// headers: {

// // 'content-type': 'application/json;charset=UTF-8'
// // "Content-Type": "application/x-www-form-urlencoded",
// "content-type":"multipart/form-data"
// },
}).then(function (res) {

console.log(res);
});

作者声明

1
如有问题,欢迎指正!