package com.rest.ws.test;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com。model.User;
import com.service.impl.UserServiceImpl;
@Path("/hello")
public class SayHelloService {
public String SUCCESS = "success";
@GET
@Produces("text/plain")
public String helloWorld(){
System.out.println("xiewenbo");
ClassPathXmlApplicationContext cxt = (ClassPathXmlApplicationContext)RestWebService.getInstance();
UserServiceImpl userservice = (UserServiceImpl)cxt.getBean("userServiceImpl",UserServiceImpl.class);
int count = userservice.findAllUsers().size();
System.out.println(count);
return "User total number is :"+count;
}
@POST
@Path("/sayhi")
@Consumes("application/x-www-form-urlencoded")
public String sayHello(@FormParam("msg")String name){
System.out.println("==============");
return "Hello "+name;
}
@GET
@Path("/save")
@Produces("text/plain")
public String addUser(){
ClassPathXmlApplicationContext cxt = (ClassPathXmlApplicationContext)RestWebService.getInstance();
UserServiceImpl userservice = (UserServiceImpl)cxt.getBean("userServiceImpl",UserServiceImpl.class);
User user = new User();
user.setUsername("xiewenbo");
user.setUserid("13061012");
user.setStatus(0);
userservice.saveUser(user);
return SUCCESS;
}
}
package com.rest.ws.test;