/**
*
*/
package net.liuweifeng.spring;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
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;
/**
*
* Spring3 MVC Demo
*
* @author liuweifeng
* @date 2010-04-26 23:24:20
*/
@Controller
@RequestMapping("/user")
public class DemoController {
private Logger logger = org.slf4j.LoggerFactory.getLogger(DemoController.class);
@RequestMapping("/index")
public void index()
{
logger.info("首页");
}
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> getUserList() {
logger.info("列表");
List<UserModel> list = new ArrayList<UserModel>();
UserModel um = new UserModel();
um.setId("1");
um.setUsername("sss");
um.setAge(222);
list.add(um);
Map<String, Object> modelMap = new HashMap<String, Object>(3);
modelMap.put("total", "1");
modelMap.put("data", list);
modelMap.put("success", "true");
return modelMap;
}
@RequestMapping(value="/{id}",method=RequestMethod.GET)
@ResponseBody
public UserModel getUserById(@PathVariable String id)
{
logger.info("取值");
UserModel um = new UserModel();
um.setId(id);
um.setUsername("sss");
um.setAge(222);
return um;
}
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> addUser(@RequestBody UserModel model)
{
logger.info("新增");
logger.info("捕获到前台传递过来的Model,名称为:"+model.getUsername());
Map<String, String> map = new HashMap<String, String>(1);
map.put("success", "true");
return map;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
helloworld_springmvc3_json.rar (34个子文件)
demo
pom.xml 4KB
.springBeans 370B
target
test-classes
log4j.xml 1KB
net
liuweifeng
spring
WelcomeControllerTests.class 626B
classes
log4j.xml 1024B
net
liuweifeng
spring
WelcomeController.class 906B
DemoController.class 3KB
UserModel.class 930B
.settings
org.eclipse.wst.common.project.facet.core.xml 222B
com.springsource.server.ide.jdt.core.xml 25B
org.springframework.ide.eclipse.beans.core.prefs 139B
org.eclipse.core.resources.prefs 117B
org.eclipse.wst.common.component 505B
org.springframework.ide.eclipse.core.prefs 11KB
org.eclipse.wst.validation.prefs 2KB
org.eclipse.jst.common.project.facet.core.prefs 229B
org.maven.ide.eclipse.prefs 262B
org.eclipse.jdt.core.prefs 617B
src
test
resources
log4j.xml 1KB
java
net
liuweifeng
spring
WelcomeControllerTests.java 226B
main
webapp
images
WEB-INF
urlrewrite.xml 489B
layouts
messages
web.xml 2KB
views
welcome.jsp 214B
user
index.jsp 1022B
classes
spring
app-config.xml 1KB
mvc-config.xml 810B
app
jquery-1.4.2.js 160KB
styles
scripts
user
index.js 1KB
resources
log4j.xml 1024B
java
net
liuweifeng
spring
DemoController.java 2KB
WelcomeController.java 690B
UserModel.java 755B
.project 1KB
.classpath 700B
共 34 条
- 1
huahoucun
- 粉丝: 25
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页