注解,自动扫描,url映射

注解自动扫描

在springmvc-config.xml添加

<context:component-scan base-package="com.cjj.no053" />
   	<mvc:annotation-driven />
   	<mvc:default-servlet-handler />
   	<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    id="internalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/view/" />
    <property name="suffix" value=".jsp" />
</bean>

当出现No mapping found for HTTP request with URI,注意namespace中

xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd “

url映射

@Controller
public class Hello {
	@RequestMapping("/hello")
	    public String SayHello(Model model) {
	        model.addAttribute("msg", "Hello,陈菁菁");
	        return "hello2";
	    }
}

@RequestMapping("/hello")是在web.xml中拦截的url名
return出来的是hello2,加在.jsp之前,根据以上是找到hello2.jsp

猜你喜欢

转载自blog.csdn.net/qq_41863865/article/details/88892294