** Learn from the station b springcloud project, now summarize the summary removal of a small error appearing in the video, some of the error-prone places were reminded
b outbound links: https://www.bilibili.com/video/av55629580?p=1
profile link:
https://pan.baidu.com/s/1o0Aju3IydKA15Vo1pP4z5w
extraction code: 21ru
On a link:
https://blog.csdn.net/qq_40893824/article/details/103618769
next section link:
https://blog.csdn.net/qq_40893824/article/details/103628646
The following list summarizes:
client / UserHandler → User / Entity new MenuVO, copy to client / entity → modify the client / UserHandler → check codes in findAll
Now go to page features user client calls the
implementation details:
Manage Users:
1. Because to use the page to show user information, modify the client / controller / UserHandler.java code for
it to @ @RestController in line 10 will UserHandler.java Controller
2. Delete update the code, findById Code
3. Modify deleteById same operation code and save the code :()
void change String, plus return "the redirect: / User / the redirect / user_manage";
@DeleteMapping change @GetMapping
/*删*/
@GetMapping("/deleteById/{id}")
public String deleteById(@PathVariable("id")long id){
user.setRegisterdate(new Date());//注册时间系统给出
userFeign.deleteById(id);
return "redirect:/user/redirect/user_manage";
}
Add 4.findAll @ResponseBody
user_manage.html there th label, so UserHandler redirect plus background map (and in the same MenuHandler) in the following code:
@GetMapping("/redirect/{location}")
public String redirect(@PathVariable("location")String location){
return location;
}
5. Because findAll returned List <> view page can not be resolved, so to user / entity new UserVO, tagging:
package com.southwind.entity;
import lombok.Data;
import java.util.List;
@Data
public class UserVO {
private int code;
private String msg;
private int count;
private List<User> data;
}
6. UserVO copied to the client / entity, and then read the code findAll:
List <the User> to UserVO, GetMapping path to the "/ findAll", 2 th @PathVariable to @RequestParam:
/*查*/
@GetMapping("/findAll")
@ResponseBody
public UserVO findAll(@RequestParam("page") int page , @RequestParam("limit") int limit){
int index = (page - 1)*limit;
UserVO userVO = new UserVO();
userVO.setCode(0);;
userVO.setMsg("");
userVO.setCount(userFeign.count());
userVO.setData(userFeign.findAll(index, limit));
return userVO;
}
Now UserHandler code:
package com.southwind.controller;
import com.southwind.entity.User;
import com.southwind.entity.UserVO;
import com.southwind.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
@Controller
@RequestMapping("/user")
public class UserHandler {
@Autowired
private UserFeign userFeign;
/*增*/
@PostMapping("/save")
public String save(User user){
user.setRegisterdate(new Date());//注册时间系统给出
userFeign.save(user);
return "redirect:/user/redirect/user_manage";
}
/*删*/
@GetMapping("/deleteById/{id}")
public String deleteById(@PathVariable("id")long id){
userFeign.deleteById(id);
return "redirect:/user/redirect/user_manage";
}
/*查*/
@GetMapping("/findAll")
@ResponseBody
public UserVO findAll(@RequestParam("page") int page , @RequestParam("limit") int limit){
int index = (page - 1)*limit;
UserVO userVO = new UserVO();
userVO.setCode(0);;
userVO.setMsg("");
userVO.setCount(userFeign.count());
userVO.setData(userFeign.findAll(index, limit));
return userVO;
}
@GetMapping("/count")
public int count(){
return userFeign.count();
}
@GetMapping("/redirect/{location}")
public String redirect(@PathVariable("location")String location){
return location;
}
}
Check
7. Go to http: // localhost: 8030 / user / redirect / user_manage
success!
Add User:
1.manage_add have th label, continue to use the redirect background mapping
enter http: // localhost: 8030 / user / redirect / user_add
added successfully!
Verify Delete: Click Delete:
Xiao Ming was successfully deleted!
On a link:
https://blog.csdn.net/qq_40893824/article/details/103618769
next section link:
https://blog.csdn.net/qq_40893824/article/details/103628646