写程序,大多的配置让人很头痛。有了注解功能,写起来就方便了许多。
在上个springmvc中
control换成
package com.conntrol;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloConntrol {
@RequestMapping(value="/hello.do")
public String hello(String name,Model model){
System.out.println(name);
model.addAttribute("hello", name);
return "index";
}
}
2.在springmvc-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: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.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<!-- 注解驱动 -->
<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>
转载于:https://blog.51cto.com/zhuws/1924239