** 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/103615379
next section link:
https://blog.csdn.net/qq_40893824/article/details/103626809
The following list summarizes:
Client / Entity / the User → Client / Feign New UserFeign.java → client / controller checks the New UserHandler.java →
Now calling user to the client function
implementation details:
1. User / entity class User entity to copy client / entity are
2. In client / feign the New Interface UserFeign.java, tagging:
package com.southwind.feign;
import com.southwind.entity.User;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@FeignClient(value = "user")
public interface UserFeign {
/*增*/
@PostMapping("/user/save")
public void save(@RequestBody User user);
/*改*/
@PutMapping("/user/update")
public void update(@RequestBody User user);
/*删*/
@DeleteMapping("/user/deleteById/{id}")
public void deleteById(@PathVariable("id")long id);
/*查*/
@GetMapping("/user/findAll/{index}/{limit}")
public List<User> findAll(@PathVariable("index")int index , @PathVariable("limit")int limit);
@GetMapping("/user/findById/{id}")
public User findById(@PathVariable("id")long id);
@GetMapping("/user/count")
public int count();
}
3. In the client / controller to control the new class UserHandler.java, tagging:
Note save @RequestBody no need to add the User, the Client does not need @RequestBody, only handle this function is achieved only need to parse data @RequestBody, just call the client does not need to parse data @RequestBody!
user / UserHandler in will add @RequestBody
package com.southwind.controller;
import com.southwind.entity.User;
import com.southwind.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/user")
public class UserHandler {
@Autowired
private UserFeign userFeign;
/*增*/
@PostMapping("/save")
public void save( User user){
userFeign.save(user);
}
@PutMapping("/update")
public void update(@RequestBody User user){
userFeign.update(user);
}
/*删*/
@DeleteMapping("/deleteById/{id}")
public void deleteById(@PathVariable("id")long id){
userFeign.deleteById(id);
}
/*查*/
@GetMapping("/findAll/{index}/{limit}")
public List<User> findAll(@PathVariable("index") int index , @PathVariable("limit") int limit){
return userFeign.findAll(index, limit);
}
@GetMapping("/findById/{id}")
public User findById(@PathVariable("id")long id){
return userFeign.findById(id);
}
@GetMapping("/count")
public int count(){
return userFeign.count();
}
}
4. Enter the HTTP: // localhost: 8030 / the User / findAll / 0/10
findAll successful call!
5. Open Postman
A into the HTTP GET:. // localhost: 8030 / the User / findAll / 0/10
findAll success!
b into the post http:. // localhost: 8030 / user / save
successfully added!
c enters put http:. // localhost: 8030 / user / update
re-entering the get http: // localhost: 8030 / user / findAll / 0/10
updated successfully!
d enter delete http:. // localhost: 8030 / user / deleteById / 7
re-entering the get http: // localhost: 8030 / user / findAll / 0/10
success!
On a link:
https://blog.csdn.net/qq_40893824/article/details/103615379
next section link:
https://blog.csdn.net/qq_40893824/article/details/103626809