Loading

spring mvc 注解示例

springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc
     http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.1.xsd">
    <!-- spring mvc 注解驱动 -->
    <mvc:annotation-driven />
    <!-- 扫描器 -->
    <context:component-scan base-package="com" />

    <!-- 配置视图 解析器 -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- 前缀和后缀 -->
        <property name="prefix" value="/view/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
</beans>

 

handler

package com.stone.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * user/list.do
 * user/add.do
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping(value = "/list.do")
    public String list() {
        System.out.println("---------查询用户信息----------");
        return "userinfo/user_list";
    }

    @RequestMapping("/add.do")
    public String add() {
        System.out.println("---------用户信息添加------------");
        return "userinfo/user_add";
    }

    @RequestMapping("/update.do")
    public String update() {
        System.out.println("---------用户信息修改------------");
        return "userinfo/user_update";
    }
}

jsp位于WebRoot/view/userinfo/user_*.jsp;

posted @ 2015-05-06 16:26  stono  阅读(305)  评论(0编辑  收藏  举报