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;

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。