package com.bill.springrest.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bill.springrest.model.User;
import com.bill.springrest.model.UserList;
@Controller
@RequestMapping("/rest/user")
public class UserController {
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody String demo() {
return "helloword";
}
@RequestMapping(method=RequestMethod.GET, value="/{userId}", headers="Accept=application/json,application/xml")
public @ResponseBody User getUser(@PathVariable int userId) {
System.out.println("userId is: " + userId);
User user = new User(); //just for demo, no db touched
user.setUserId(userId);
user.setUserName("Bill");
return user;
}
@RequestMapping(method=RequestMethod.POST)
public @ResponseBody void putUser(@RequestBody User user) {
if (user != null) {
System.out.println("userId: " + user.getUserId());
System.out.println("userName: " + user.getUserName());
}
}
@RequestMapping(method=RequestMethod.GET, value="/all", headers="Accept=application/json,application/xml")
public @ResponseBody UserList getUserList() {
List<User> userList = new ArrayList<User>();
User user1 = new User(); //just for demo, no db touched
user1.setUserId(1);
user1.setUserName("Bill");
userList.add(user1);
User user2 = new User();
user2.setUserId(2);
user2.setUserName("John");
userList.add(user2);
UserList userListFinal = new UserList(userList);
return userListFinal;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
springrest.rar (28个子文件)
springrest
pom.xml 4KB
.settings
org.maven.ide.eclipse.prefs 249B
org.eclipse.jdt.core.prefs 274B
src
test
resources
java
main
webapp
WEB-INF
springrest-servlet.xml 2KB
web.xml 2KB
jdbc.properties 380B
log4j.properties 821B
jsp
InfoPage.jsp 661B
.svn
prop-base
props
tmp
prop-base
props
text-base
text-base
CampaignList.jsp.svn-base 5KB
AdvertiserHome.jsp.svn-base 5KB
OrderList.jsp.svn-base 5KB
BannerList.jsp.svn-base 8KB
ErrorPage.jsp.svn-base 1KB
BannerUpdate.jsp.svn-base 3KB
InfoPage.jsp.svn-base 661B
jboss-deployment-structure.xml 231B
.svn
prop-base
props
tmp
prop-base
applicationContext.xml.tmp 5KB
props
text-base
text-base
jdbc.properties.svn-base 380B
applicationContext.xml.svn-base 4KB
adserver-servlet.xml.svn-base 551B
log4j.properties.svn-base 821B
jboss-deployment-structure.xml.svn-base 231B
applicationContext.xml 2KB
resources
java
com
bill
springrest
model
User.java 1KB
UserList.java 806B
controller
UserController.java 2KB
.project 564B
.classpath 709B
共 28 条
- 1
taoyuanforrest
- 粉丝: 98
- 资源: 45
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页