您的位置:首页 > 编程语言 > Java开发

spring-mvc开发模式相关配置

2016-08-12 09:59 337 查看
 

1.web.xml文件配置

<!-- 1.配置DispatcherServlet -->

  <servlet>

  <servlet-name>springmvc</servlet-name>

  <servlet-class>

  org.springframework.web.servlet.DispatcherServlet

  </servlet-class>

  <init-param>

  <param-name>contextConfigLocation</param-name>

  <param-value>classpath:conf/spring-*.xml</param-value>

  </init-param>

  <load-on-startup>1</load-on-startup>

  </servlet>

  <servlet-mapping>

  <servlet-name>springmvc</servlet-name>

  <url-pattern>/</url-pattern>

  </servlet-mapping>
 

2.spring-mvc.xml文件配置

<!-- 定义HandlerMapping -->
<mvc:annotation-driven />

<!-- 扫描Controller,Service组件 -->
<context:component-scan base-package="**"/>

<!-- 配置视图解析器。-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
 
</bean>

相关注解:

1.业务层 @Service("**")

2.控制层 @Controller

3.依赖注入  @Resource
private ** service;

4.请求分配  @RequestMapping("/toIndex")

5.返回视图及重定向 return "homepage";

return "redirect:/toLogin";

6.实体类及dao接口由mybatis进行关联
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: