标签:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 从类路径下加载Spring配置文件,classpath关键字特指从类路径下加载 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 负责启动Spring容器的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置Spring MVC,其对应的配置文件为:servlet-name-servlet.xml, 本项目的为:spring-servlet.xml -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
package com.ll.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ll.model.Person;
@Controller
@RequestMapping(value = "/test")
public class TestController {
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> getUserList() {
List<Person> list = new ArrayList<Person>();
Person user1 = new Person();
user1.setUsername("Tom");
user1.setPasswd("66666");
Person user2 = new Person();
user2.setUsername("Jone");
user2.setPasswd("88888");
list.add(user1);
list.add(user2);
Map<String, Object> modelMap = new HashMap<String, Object>(3);
modelMap.put("Work", "研发");
modelMap.put("School","Suzhou");
modelMap.put("userList",list);
return modelMap;
}
}
【Spring学习笔记-MVC-3.1】SpringMVC返回Json数据-方式1-扩展
标签:
原文地址:http://www.cnblogs.com/ssslinppp/p/4675495.html