29.1 java代码如下:

package com.eduask.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class Demo2 {
@RequestMapping("/testRedirect")
public String getRedirect(){
return "redirect:/demo2";
}
//重定向映射路径
@RequestMapping("/demo2")
public String getRedirect1(){
return "demo2";
}
}

29.2 springmvc-servlet.xml配置文件:

<!-- 配置适配解析器 -->
<context:component-scan base-package="com.eduask"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:view-controller path="/demo2" view-name="demo2"/>
<!-- 启动mvc-->
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>

29.程序运行如下:

30 SpringMvc中的List集合
30.1 java代码如下:
@Controller
public class Demo3 {
@ResponseBody
@RequestMapping("/demo3")
public List<User> getUser(){
List<User> user=new ArrayList<User>();
User u=new User("tom", "123456", 5000, 20);
user.add(u);
System.out.println(u);
return user;
}

30.2 springmvc-servlet配置如下:

<!-- 配置适配解析器 -->

<context:component-scan base-package="com.eduask"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:view-controller path="/demo3" view-name="/user/list"/>
<!--启动mvc-->
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>