Skip to content

Commit 17284eb

Browse files
committed
url
1 parent b87cffe commit 17284eb

5 files changed

Lines changed: 52 additions & 41 deletions

File tree

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.data.domain.Page;
1010
import org.springframework.data.domain.PageRequest;
11-
import org.springframework.web.bind.annotation.*;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RequestMethod;
13+
import org.springframework.web.bind.annotation.RequestParam;
14+
import org.springframework.web.bind.annotation.RestController;
1215

1316
import java.util.HashMap;
1417
import java.util.Map;
@@ -90,8 +93,8 @@ public HashMap<String, Object> register(
9093
return result;
9194
}
9295

93-
@RequestMapping(value = "findById/{id}", method = RequestMethod.GET)
94-
public HashMap<String, Object> findUserById(@PathVariable("id") Long id) {
96+
@RequestMapping(value = "findById", method = RequestMethod.GET)
97+
public HashMap<String, Object> findUserById(@RequestParam("id") Long id) {
9598
AdminModel adminModel = service.findAdminUserById(id);
9699
if (adminModel == null) {
97100
result.put(code, notFound);
@@ -103,16 +106,16 @@ public HashMap<String, Object> findUserById(@PathVariable("id") Long id) {
103106
}
104107

105108

106-
@RequestMapping(value = "findAll/{start}/{pageSize}", method = RequestMethod.GET)
107-
public HashMap<String, Object> getAll(@PathVariable("start") int start, @PathVariable("pageSize") int page) {
109+
@RequestMapping(value = "findAll", method = RequestMethod.GET)
110+
public HashMap<String, Object> getAll(@RequestParam("start") int start, @RequestParam("pageSize") int page) {
108111
Page<AdminModel> pages = service.getAdminUsers(new PageRequest(start - 1, page));
109112
result.put(code, success);
110113
result.put("adminUsers", pages);
111114
return result;
112115
}
113116

114-
@RequestMapping(value = "deleteById/{id}", method = RequestMethod.GET)
115-
public HashMap<String, Object> deleteUserById(@PathVariable("id") Long id) throws UserNotFoundException {
117+
@RequestMapping(value = "deleteById", method = RequestMethod.GET)
118+
public HashMap<String, Object> deleteUserById(@RequestParam("id") Long id) throws UserNotFoundException {
116119
AdminModel adminModel = service.deleteAdminUserById(id);
117120
if (adminModel == null) {
118121
result.put(code, notFound);
@@ -143,8 +146,8 @@ public HashMap<String, Object> update(
143146
return result;
144147
}
145148

146-
@RequestMapping(value = "forbid/{id}", method = RequestMethod.GET)
147-
public HashMap<String, Object> forbid(@PathVariable("id") Long id) throws UserNotFoundException {
149+
@RequestMapping(value = "forbid", method = RequestMethod.GET)
150+
public HashMap<String, Object> forbid(@RequestParam("id") Long id) throws UserNotFoundException {
148151
AdminModel model = service.findAdminUserById(id);
149152
if (model == null) {
150153
result.put(code, notFound);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import org.springframework.beans.factory.annotation.Autowired;
88
import org.springframework.data.domain.Page;
99
import org.springframework.data.domain.PageRequest;
10-
import org.springframework.web.bind.annotation.PathVariable;
1110
import org.springframework.web.bind.annotation.RequestMapping;
1211
import org.springframework.web.bind.annotation.RequestMethod;
12+
import org.springframework.web.bind.annotation.RequestParam;
1313
import org.springframework.web.bind.annotation.RestController;
1414

1515
import java.util.HashMap;
@@ -41,8 +41,8 @@ public class UserController extends BaseController {
4141
* @param id id
4242
* @return result
4343
*/
44-
@RequestMapping(value = "findById/{id}", method = RequestMethod.GET)
45-
public HashMap<String, Object> findUserById(@PathVariable("id") Long id) {
44+
@RequestMapping(value = "findById", method = RequestMethod.GET)
45+
public HashMap<String, Object> findUserById(@RequestParam("id") Long id) {
4646
UserModel userModel = service.findUserById(id);
4747
if (userModel == null) {
4848
result.put(code, notFound);
@@ -60,8 +60,8 @@ public HashMap<String, Object> findUserById(@PathVariable("id") Long id) {
6060
* @param page page
6161
* @return result
6262
*/
63-
@RequestMapping(value = "findAll/{start}/{pageSize}", method = RequestMethod.GET)
64-
public HashMap<String, Object> getAll(@PathVariable("start") int start, @PathVariable("pageSize") int page) {
63+
@RequestMapping(value = "findAll", method = RequestMethod.GET)
64+
public HashMap<String, Object> getAll(@RequestParam("start") int start, @RequestParam("pageSize") int page) {
6565
Page<UserModel> pages = service.getUsers(new PageRequest(start - 1, page));
6666
result.put(code, success);
6767
result.put("users", pages);
@@ -75,8 +75,8 @@ public HashMap<String, Object> getAll(@PathVariable("start") int start, @PathVar
7575
* @return result
7676
* @throws UserNotFoundException
7777
*/
78-
@RequestMapping(value = "deleteById/{id}", method = RequestMethod.GET)
79-
public HashMap<String, Object> deleteUserById(@PathVariable("id") Long id) throws UserNotFoundException {
78+
@RequestMapping(value = "deleteById", method = RequestMethod.GET)
79+
public HashMap<String, Object> deleteUserById(@RequestParam("id") Long id) throws UserNotFoundException {
8080
UserModel userModel = service.deleteUserById(id);
8181
if (userModel == null) {
8282
result.put(code, notFound);

core/src/main/java/info/xiaomo/core/controller/BaseController.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import info.xiaomo.core.model.base.BaseModel;
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
6-
import org.springframework.web.bind.annotation.PathVariable;
76
import org.springframework.web.bind.annotation.RequestMapping;
87
import org.springframework.web.bind.annotation.RequestMethod;
98
import org.springframework.web.bind.annotation.RequestParam;
@@ -60,16 +59,16 @@ public abstract class BaseController<E extends BaseModel> {
6059
* 找不到
6160
*/
6261
protected static final int notFound = 404;
63-
/**
64-
* result
65-
*/
66-
protected HashMap<String, Object> result = new HashMap<>();
6762
/**
6863
* 跨域处理
6964
* 后端需要加个callback
7065
* 前端要使用jsoup
7166
*/
7267
protected final Logger logger = LoggerFactory.getLogger(getClass());
68+
/**
69+
* result
70+
*/
71+
protected HashMap<String, Object> result = new HashMap<>();
7372

7473
/**
7574
* 跨域处理
@@ -92,8 +91,8 @@ protected void crossDomain(HttpServletResponse response) {
9291
* @param id id
9392
* @return return
9493
*/
95-
@RequestMapping(value = "findById/{id}", method = RequestMethod.GET)
96-
public HashMap<String, Object> findById(@PathVariable("id") Long id) {
94+
@RequestMapping(value = "findById", method = RequestMethod.GET)
95+
public HashMap<String, Object> findById(@RequestParam("id") Long id) {
9796
return result;
9897
}
9998

@@ -104,8 +103,8 @@ public HashMap<String, Object> findById(@PathVariable("id") Long id) {
104103
* @param pageSize pageSize
105104
* @return
106105
*/
107-
@RequestMapping(value = "findAll/{start}/{pageSize}", method = RequestMethod.GET)
108-
public HashMap<String, Object> RequestParam(@PathVariable("start") int start, @PathVariable("pageSize") int pageSize) {
106+
@RequestMapping(value = "findAll", method = RequestMethod.GET)
107+
public HashMap<String, Object> RequestParam(@RequestParam("start") int start, @RequestParam("pageSize") int pageSize) {
109108
return result;
110109
}
111110

@@ -137,8 +136,8 @@ public HashMap<String, Object> add(@RequestParam String params) {
137136
* @param id id
138137
* @return result
139138
*/
140-
@RequestMapping(value = "deleteById/{id}", method = RequestMethod.GET)
141-
public HashMap<String, Object> deleteById(@PathVariable("id") Long id) {
139+
@RequestMapping(value = "deleteById/", method = RequestMethod.GET)
140+
public HashMap<String, Object> deleteById(@RequestParam("id") Long id) {
142141
return result;
143142
}
144143

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.data.domain.Page;
88
import org.springframework.data.domain.PageRequest;
9-
import org.springframework.web.bind.annotation.*;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestMethod;
11+
import org.springframework.web.bind.annotation.RequestParam;
12+
import org.springframework.web.bind.annotation.RestController;
1013

1114
import java.util.Date;
1215
import java.util.HashMap;
@@ -34,11 +37,12 @@ public class BlogController extends BaseController {
3437

3538
/**
3639
* findById
40+
*
3741
* @param id id
3842
* @return result
3943
*/
40-
@RequestMapping(value = "findById/{id}", method = RequestMethod.GET)
41-
public HashMap<String, Object> findById(@PathVariable Long id) {
44+
@RequestMapping(value = "findById/", method = RequestMethod.GET)
45+
public HashMap<String, Object> findById(@RequestParam Long id) {
4246
BlogModel model = service.findBlogById(id);
4347
if (model == null) {
4448
result.put(code, notFound);
@@ -51,12 +55,13 @@ public HashMap<String, Object> findById(@PathVariable Long id) {
5155

5256
/**
5357
* 分页查询
54-
* @param start start
58+
*
59+
* @param start start
5560
* @param pageSize pageSize
5661
* @return result
5762
*/
58-
@RequestMapping(value = "findAll/{start}/{pageSize}", method = RequestMethod.GET)
59-
public HashMap<String, Object> findAll(@PathVariable("start") int start, @PathVariable("pageSize") int pageSize) {
63+
@RequestMapping(value = "findAll", method = RequestMethod.GET)
64+
public HashMap<String, Object> findAll(@RequestParam("start") int start, @RequestParam("pageSize") int pageSize) {
6065
Page<BlogModel> models = service.findAll(new PageRequest(start, pageSize));
6166
result.put(code, success);
6267
result.put("blogs", models);
@@ -65,10 +70,11 @@ public HashMap<String, Object> findAll(@PathVariable("start") int start, @PathVa
6570

6671
/**
6772
* 增加博客
68-
* @param title title
73+
*
74+
* @param title title
6975
* @param summary summary
7076
* @param content content
71-
* @param tagId tagId
77+
* @param tagId tagId
7278
* @return result
7379
*/
7480
@RequestMapping(value = "add", method = RequestMethod.POST)
@@ -96,7 +102,7 @@ public HashMap<String, Object> add(
96102
return result;
97103
}
98104

99-
@RequestMapping(value = "update",method = RequestMethod.POST)
105+
@RequestMapping(value = "update", method = RequestMethod.POST)
100106
public HashMap<String, Object> update(@RequestParam String params) {
101107
return result;
102108
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
1313
import org.springframework.beans.factory.annotation.Autowired;
14-
import org.springframework.web.bind.annotation.*;
14+
import org.springframework.web.bind.annotation.RequestMapping;
15+
import org.springframework.web.bind.annotation.RequestMethod;
16+
import org.springframework.web.bind.annotation.RequestParam;
17+
import org.springframework.web.bind.annotation.RestController;
1518

1619
import java.text.ParseException;
1720
import java.util.Date;
@@ -127,8 +130,8 @@ public HashMap<String, Object> register(
127130
* @param email email
128131
* @return result
129132
*/
130-
@RequestMapping(value = "findById/{email}", method = RequestMethod.GET)
131-
public Map<String, Object> findUserByEmail(@PathVariable("email") String email) {
133+
@RequestMapping(value = "findByEmail", method = RequestMethod.GET)
134+
public Map<String, Object> findUserByEmail(@RequestParam("email") String email) {
132135
UserModel userModel = service.findUserByEmail(email);
133136
if (userModel == null) {
134137
result.put(code, notFound);
@@ -146,8 +149,8 @@ public Map<String, Object> findUserByEmail(@PathVariable("email") String email)
146149
* @param id id
147150
* @return result
148151
*/
149-
@RequestMapping(value = "findById/{id}", method = RequestMethod.GET)
150-
public HashMap<String, Object> findUserById(@PathVariable("id") Long id) {
152+
@RequestMapping(value = "findById", method = RequestMethod.GET)
153+
public HashMap<String, Object> findUserById(@RequestParam("id") Long id) {
151154
UserModel userModel = service.findUserById(id);
152155
if (userModel == null) {
153156
result.put(code, notFound);

0 commit comments

Comments
 (0)