@Controller
@ResponseBody
public class UserController {
//http:localhost:8080/hello
@RequestMapping("/hello")
public String hello(){
return "您好";
}
@RequestMapping("/findUserByNA")
public String findUserByNA(String name,int age){
return name+":"+age;
}
@RequestMapping("/findUserByNA2")
public String findUserByNA2(User user){
return user.toString();
}
@RequestMapping("/hobby")
public String hobby(String[] hobby){
// return Arrays.toString(hobby);
// String[] split = hobby.split(",");
return Arrays.toString(hobby);
// return Arrays.toString(hobby);
}
// @RequestMapping("/findUser/{name}/{age}/{sex}")
public String findUser(@PathVariable String name,@PathVariable int age, @PathVariable String sex){
return name+":"+age+sex;
}
@RequestMapping("/findUser/{name}/{age}/{sex}")
public String findUser(User user){
return user.toString();
}
//http://localhost:8080/findJSON?name=tomacat&age=18
@RequestMapping("/findJSON")
@ResponseBody
public User findJSON(User user) {
user.setId(101);
user.setSex("男");
return user;
}
}