spring mvc 3 在netbeans中的默认注解配置

(1)dispatcher-servlet.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:tx="http://www.springframework.org/schema/tx" 
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- Scans the classpath of this application for @Components to deploy as beans -->
    <context:component-scan base-package="com.yyw.controller" />
    
   
    
    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />

    <bean id="viewresolver"
           class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean> 
</beans>

(2)Controller

@Controller
@RequestMapping(value = "demo")
public class DemoController {

    @RequestMapping(value = "login")
    public String login(ModelMap modelmap) {
        Account account = new Account();
        account.setId("1");
        account.setName("Peter");
        if (account != null) {
            modelmap.put("account", account);
        } else {
            account.setId("123");
            account.setName("123");
            modelmap.put("account", account);            
        }
        return "loginForm";
    }
}

 

posted @ 2013-01-29 08:58  Peter_youny  阅读(620)  评论(0)    收藏  举报