Skip to content

Commit 64d4e97

Browse files
committed
指定method
1 parent fbc2304 commit 64d4e97

3 files changed

Lines changed: 22 additions & 27 deletions

File tree

admin/src/main/java/info/xiaomo/admin/controller/AdminUserController.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
import info.xiaomo.core.exception.UserNotFoundException;
55
import info.xiaomo.core.model.AdminModel;
66
import info.xiaomo.core.service.AdminUserService;
7+
import info.xiaomo.core.untils.MD5;
78
import org.springframework.beans.factory.annotation.Autowired;
89
import org.springframework.data.domain.Page;
910
import org.springframework.data.domain.PageRequest;
10-
import org.springframework.web.bind.annotation.PathVariable;
11-
import org.springframework.web.bind.annotation.RequestMapping;
12-
import org.springframework.web.bind.annotation.RequestParam;
13-
import org.springframework.web.bind.annotation.RestController;
11+
import org.springframework.web.bind.annotation.*;
1412

1513
import java.util.HashMap;
1614
import java.util.Map;
@@ -44,14 +42,14 @@ public class AdminUserController extends BaseController {
4442
@Autowired
4543
AdminUserService service;
4644

47-
@RequestMapping("login")
45+
@RequestMapping(value = "login", method = RequestMethod.POST)
4846
public Map<String, Object> login(@RequestParam String userName, @RequestParam String password) {
4947
HashMap<String, java.lang.Object> result = new HashMap<>();
5048
AdminModel adminModel = service.findAdminUserByUserName(userName);
5149
if (adminModel == null) {
5250
result.put(code, notFound);
5351
} else {
54-
if (password.equals(adminModel.getPassword())) {
52+
if (MD5.encode(password).equals(adminModel.getPassword())) {
5553
result.put(code, success);
5654
result.put("adminUser", adminModel);
5755
} else {
@@ -61,7 +59,7 @@ public Map<String, Object> login(@RequestParam String userName, @RequestParam St
6159
return result;
6260
}
6361

64-
@RequestMapping("findById/{id}")
62+
@RequestMapping(value = "findById/{id}", method = RequestMethod.GET)
6563
public HashMap<String, Object> findUserById(@PathVariable("id") Long id) {
6664
HashMap<String, Object> result = new HashMap<>();
6765
AdminModel adminModel = service.findAdminUserById(id);
@@ -76,7 +74,7 @@ public HashMap<String, Object> findUserById(@PathVariable("id") Long id) {
7674
}
7775

7876

79-
@RequestMapping("findAll/{start}/{pageSize}")
77+
@RequestMapping(value = "findAll/{start}/{pageSize}", method = RequestMethod.GET)
8078
public HashMap<String, Object> getAll(@PathVariable("start") int start, @PathVariable("pageSize") int page) {
8179
HashMap<String, Object> result = new HashMap<>();
8280
Page<AdminModel> pages = service.getAdminUsers(new PageRequest(start - 1, page));
@@ -98,11 +96,11 @@ public HashMap<String, Object> deleteUserById(@PathVariable("id") Long id) throw
9896
return result;
9997
}
10098

101-
@RequestMapping("update/{userName}/{password}/{authLevel}")
99+
@RequestMapping(value = "update", method = RequestMethod.POST)
102100
public HashMap<String, Object> update(
103-
@PathVariable("userName") String userName,
104-
@PathVariable("password") String password,
105-
@PathVariable("authLevel") int authLevel
101+
@RequestParam("userName") String userName,
102+
@RequestParam("password") String password,
103+
@RequestParam("authLevel") int authLevel
106104
) {
107105
HashMap<String, Object> result = new HashMap<>();
108106
AdminModel adminModel = service.findAdminUserByUserName(userName);
@@ -118,7 +116,7 @@ public HashMap<String, Object> update(
118116
return result;
119117
}
120118

121-
@RequestMapping("forbid/{id}")
119+
@RequestMapping(value = "forbid/{id}", method = RequestMethod.GET)
122120
public HashMap<String, Object> forbid(@PathVariable("id") Long id) throws UserNotFoundException {
123121
HashMap<String, Object> result = new HashMap<>();
124122
AdminModel model = service.findAdminUserById(id);
@@ -127,7 +125,7 @@ public HashMap<String, Object> forbid(@PathVariable("id") Long id) throws UserNo
127125
} else {
128126
model = service.forbidAdminUserById(id);
129127
result.put(code, success);
130-
result.put("user", model);
128+
result.put("adminUser", model);
131129
}
132130
return result;
133131
}

admin/src/main/java/info/xiaomo/admin/controller/UserController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.springframework.data.domain.PageRequest;
1010
import org.springframework.web.bind.annotation.PathVariable;
1111
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RequestMethod;
1213
import org.springframework.web.bind.annotation.RestController;
1314

1415
import java.util.HashMap;
@@ -34,7 +35,7 @@ public class UserController extends BaseController {
3435
@Autowired
3536
private UserService service;
3637

37-
@RequestMapping("findById/{id}")
38+
@RequestMapping(value = "findById/{id}", method = RequestMethod.GET)
3839
public HashMap<String, Object> findUserById(@PathVariable("id") Long id) {
3940
HashMap<String, Object> result = new HashMap<>();
4041
UserModel userModel = service.findUserById(id);
@@ -47,8 +48,7 @@ public HashMap<String, Object> findUserById(@PathVariable("id") Long id) {
4748
return result;
4849
}
4950

50-
51-
@RequestMapping("findAll/{start}/{pageSize}")
51+
@RequestMapping(value = "findAll/{start}/{pageSize}", method = RequestMethod.GET)
5252
public HashMap<String, Object> getAll(@PathVariable("start") int start, @PathVariable("pageSize") int page) {
5353
HashMap<String, Object> result = new HashMap<>();
5454
Page<UserModel> pages = service.getUsers(new PageRequest(start - 1, page));
@@ -57,7 +57,7 @@ public HashMap<String, Object> getAll(@PathVariable("start") int start, @PathVar
5757
return result;
5858
}
5959

60-
@RequestMapping("deleteById/{id}")
60+
@RequestMapping(value = "deleteById/{id}", method = RequestMethod.GET)
6161
public HashMap<String, Object> deleteUserById(@PathVariable("id") Long id) throws UserNotFoundException {
6262
HashMap<String, Object> result = new HashMap<>();
6363
UserModel userModel = service.deleteUserById(id);

web/src/main/java/info/xiaomo/web/controller/UserController.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
import info.xiaomo.core.service.UserService;
77
import info.xiaomo.core.untils.MD5;
88
import org.springframework.beans.factory.annotation.Autowired;
9-
import org.springframework.web.bind.annotation.PathVariable;
10-
import org.springframework.web.bind.annotation.RequestMapping;
11-
import org.springframework.web.bind.annotation.RequestParam;
12-
import org.springframework.web.bind.annotation.RestController;
9+
import org.springframework.web.bind.annotation.*;
1310

1411
import java.util.HashMap;
1512

@@ -34,8 +31,8 @@ public class UserController extends BaseController {
3431
@Autowired
3532
private UserService service;
3633

37-
@RequestMapping("login/{userName}/{password}")
38-
public HashMap<String, Object> login(@PathVariable String userName, @PathVariable String password) {
34+
@RequestMapping(value = "login", method = RequestMethod.POST)
35+
public HashMap<String, Object> login(@RequestParam String userName, @RequestParam String password) {
3936
HashMap<String, Object> result = new HashMap<>();
4037
UserModel userModel = service.findUserByUserName(userName);
4138
if (userModel == null) {
@@ -52,7 +49,7 @@ public HashMap<String, Object> login(@PathVariable String userName, @PathVariabl
5249
}
5350

5451

55-
@RequestMapping("register")
52+
@RequestMapping(value = "register", method = RequestMethod.POST)
5653
public HashMap<String, Object> register(
5754
@RequestParam String userName,
5855
@RequestParam String nickName,
@@ -87,12 +84,12 @@ public HashMap<String, Object> register(
8784
}
8885

8986

90-
@RequestMapping("findById/{id}")
87+
@RequestMapping(value = "findById/{id}", method = RequestMethod.GET)
9188
public UserModel findUserById(@PathVariable("id") Long id) {
9289
return service.findUserById(id);
9390
}
9491

95-
@RequestMapping("update")
92+
@RequestMapping(value = "update", method = RequestMethod.POST)
9693
public HashMap<String, Object> update(
9794
@RequestParam String userName,
9895
@RequestParam String nickName,

0 commit comments

Comments
 (0)