发表于: 2017-05-10 23:05:18

3 1252


Task2的第二天


今日计划

  1. 学习Spring MVC

今日完成

配置Spring MVC

第一步:老规矩,添加依赖

<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>4.3.7.RELEASE</version>
</dependency>

第二步:修改<web-app>标签

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
        version="3.1">

第三步:配置DispatcherServlet

  <!-- 配置DispatcherServlet -->
 <servlet>
   <display-name>SSM</display-name>
   <servlet-name>dispatcher</servlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
   <!-- 配置springMVC需要加载的配置文件
       spring-dao.xml,spring-service.xml,spring-web.xml
    -->
   <init-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>classpath:spring/spring-*.xml</param-value>
   </init-param>
 </servlet>

 <servlet-mapping>
   <servlet-name>dispatcher</servlet-name>
   <!-- 默认匹配所有的请求 -->
   <url-pattern>/</url-pattern>
 </servlet-mapping>

第四步:配置spring-service.xml

<!-- 扫描service包下所有使用注解的类型 -->
<context:component-scan base-package="com.semonx.jnshu.service">
   <!-- 只扫描标记了Service的类 -->
   <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>

<!-- 配置事务管理器 -->
<bean id="transactionManager"
     class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <!-- 注入数据库连接池 -->
   <property name="dataSource" ref="dataSource"/>
</bean>

<!-- 配置基于注解的声明式事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>

昨天方向错了,JSON不是靠ContentNegotiatingViewResolver完成的,是靠Converter转换器完成的。方向错了,今天重新看。

明日计划

明天请假,为什么答辩完还要该论文!

问题总结

中间中断了几天,发现好多东西都不熟悉了……



返回列表 返回列表
评论

    分享到