添加操作
服务端
@POST
public void saveUser ( User user) ;
客户端
@Test
public void testSaveUser ( ) {
WebClient
. create ( "http://localhost:9000/userService" )
. post ( new User ( 1 , "小张" , "男" ) ) ;
}
修改操作
服务端
@PUT
public void updateUser ( User user) ;
客户端
@Test
public void testUpdateUser ( ) {
WebClient
. create ( "http://localhost:9000/userService" )
. put ( new User ( 2 , "小红" , "女" ) ) ;
}
删除操作
服务端
@DELETE
@Path ( "/{id}" )
public void deleteUser ( @PathParam ( "id" ) Integer id) ;
客户端
@Test
public void testDeleteUser ( ) {
WebClient
. create ( "http://localhost:9000/userService/10" )
. delete ( ) ;
}
查询所有数据
服务端
@GET
public List < User > findAllUser ( ) ;
客户端
@Test
public void testFindAllUser ( ) {
List < User > list = ( List < User > ) WebClient
. create ( "http://localhost:9000/userService" )
. getCollection ( User . class ) ;
for ( User user : list) {
System . out. println ( user) ;
}
}
查询一个数据
服务端
@GET
@Path ( "/{id}" )
public User findById ( @PathParam ( "id" ) Integer id) ;
客户端
@Test
public void testFindById ( ) {
User user = WebClient
. create ( "http://localhost:9000/userService/1" )
. get ( User . class ) ;
System . out. println ( user) ;
}