Day03:cloud_note云笔记项目完成记录--1

cloud_note云笔记项目完成记录

项目github地址

暑期实训云笔记项目记录。

1.环境搭建

  • 创建Maven项目
  • 生成web.xml
  • 导入目标运行环境:Tomcat运行环境

2.以上三步在Day01,Day02都已完成


3. 通过pom.xml文件导入需要的包

<dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-webmvcartifactId>
    <version>3.2.8.RELEASEversion>
dependency>

<dependency>
    <groupId>com.fasterxml.jackson.coregroupId>
    <artifactId>jackson-coreartifactId>
    <version>2.8.5version>
dependency>

<dependency>
    <groupId>com.fasterxml.jackson.coregroupId>
    <artifactId>jackson-databindartifactId>
    <version>2.8.5version>
dependency>

<dependency>
    <groupId>com.fasterxml.jackson.coregroupId>
    <artifactId>jackson-annotationsartifactId>
    <version>2.8.5version>
dependency>


<dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-jdbcartifactId>
    <version>3.2.8.RELEASEversion>
dependency>

<dependency>
    <groupId>org.mybatisgroupId>
    <artifactId>mybatisartifactId>
    <version>3.4.0version>
dependency>

<dependency>
    <groupId>org.mybatisgroupId>
    <artifactId>mybatis-springartifactId>
    <version>1.3.1version>
dependency>

<dependency>
    <groupId>MysqlgroupId>
    <artifactId>mysql-connector-javaartifactId>
    <version>5.1.38version>
dependency>

<dependency>
    <groupId>commons-dbcpgroupId>
    <artifactId>commons-dbcpartifactId>
    <version>1.4version>
dependency>

<dependency>
    <groupId>junitgroupId>
    <artifactId>junitartifactId>
    <version>4.12version>
dependency>

4.配置Spring MVC控制器: web.xml

 <servlet>
    <description>description>
    <display-name>DispatcherServletdisplay-name>
    <servlet-name>DispatcherServletservlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    <init-param>
      <description>description>
      <param-name>contextConfigLocationparam-name>
      <param-value>classpath:conf/spring-*.xmlparam-value>
    init-param>
    <load-on-startup>1load-on-startup>
  servlet>
  <servlet-mapping>
    <servlet-name>DispatcherServletservlet-name>
    <url-pattern>*.dourl-pattern>
  servlet-mapping>

5.添加Spring-MVC 配置文件: conf/spring-mvc.xml


<context:component-scan 
    base-package="cn.tedu.note.controller"/>

<mvc:annotation-driven />

6.配置MyBatis: conf/spring-mybatis.xml


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    
    <property name="driverClassName" value="com.mysql.jdbc.Driver">property>
    <property name="url" value="jdbc:mysql://localhost:3306/cloud_note">property> 
    <property name="username" value="root">property>
    <property name="password" value="">property>
    
    <property name="maxActive" value="50">property> 
    <property name="initialSize" value="5">property> 
    <property name="maxIdle" value="5">property> 
bean>


<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource">property>
    

    <property name="mapperLocations" value="classpath:mapper/*.xml">property>

bean>


<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    
    <property name="basePackage" value="cn.tedu.note.dao">property> 
bean>

7.部署测试

你可能感兴趣的:(springmvc,JavaWeb)