技术选型:

一.项目搭建:

1)创建maven项目 (我博客里面有介绍)

  选择aptach的maven-archetype-webapp

  填入groupIDhe artifactId等

  确认项目名称

  maven插件会自动生成项目结构

2)添加其他目录

  在/src/main下添加java目录(命名自己定),设置为源码根目录

  注:有需要的话可以在src目录下添加测试相关代码的目录

  建立如下目录结构(自己定)

    com.xx.common

    com.xx.vip

        .entity

        .dao

        .function

        .web

        -formbean

        -handler

  在webapp下建立static(放静态资源) 在webapp/WEB-INF/views(放jsp页面)

  注意:web.xml版本头一定是3.0以上的

3)修改项目和模块的语言级别为java1.8

  默认的LanguageLevel和JavaCompiler都是1.5

  需要在pom.xml中添加如下代码,制定maven变异插件maven-compiler-plugin的版本

在<build>标签中设置

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<plugin>
<plugins>

二.集成springMVC

在http://mvnrepository.com/网站搜索依赖库

1)在pom.xml中添加依赖

  spring-mvc

  servlet-api

  jstl

2)在src/main/resources目录下添加spring-mvc.xml配置文件

  a)添加注解驱动<mvc:annotation-driven />

  b)注册视图解析器

  c) 扫描mvc组件

<?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:aop="http://www.springframework.org/schema/aop"
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-4.3.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-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd"> <!-- 使用注解来请求映射 -->
<mvc:annotation-driven/>   <!-- 配置自动扫描包 -->
<context:component-scan base-package="com.cc8w.Controller"></context:component-scan> <bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 重定向是否添加上下文路径-->
<property name="redirectContextRelative" value="true"></property>
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean> </beans>

3)在web.xml中配置spring-mvc前端控制器DispatcherServlet

  a)配置随服务启动而初始化

  b)配置参数contextConfigLocation,指向spring-mvc的路径(默认在WEB-INF/和servlet-Name一样)

  c)配置servlet-mapping(可以仅处理*.do请求)

<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

4)web.xml配置请求和应答字符编码处理器(配置过滤器)

  CharacterEncodingFilter

<filter>
<description>请求和应答字符编码过滤器</description>
<filter-name>encoding-filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding-filter</filter-name>
<!--注意这里和下面配置一致-->
<servlet-name>spring-mvc</servlet-name>
</filter-mapping>

5)配置404,50X,欢迎等特殊页面(忽略)

6)编写测试案例

三.集成spring

1)添加spring依赖

  其实没有,因为添加spring-mvc时,已经把spring的核心添加了

2)编写配置文件spring-context.xml(applicationContext.xml)

  配置注解事务管理

  扫描业务层组件(配置上下文扫描)

3)在web.xml中配置ContextLoaderListener监听器,启用Spring容器

  配置ContextConfigLocation,指定spring-context.xml路径

  在web.xml配置监听器(在filter和servlet中间)

<listener>
<descripting>启动spring容器</descripting>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-context.xml</param-value>
</context-param>

四.集成c3p0

1)添加依赖

  c3p0,jdbc-mysql

2)在spring-context中定义c3p0数据源 CombopooledDaraSource

  配置属性

    基础信息

    driverClass/jdbcurl/user/password

    链接数相关

    initialPoolSize/minPoolSize/maxPoolSize/acquireIncrement

    其他属性请参见相关文档

    

maven初始搭建一个基础项目(spring mvc+spring+jdbc mysql+jstl)的更多相关文章

  1. freemarker + spring mvc + spring + mybatis + mysql + maven项目搭建

    今天说说搭建项目,使用freemarker + spring mvc + spring + mybatis + mysql + maven搭建web项目. 先假设您已经配置好eclipse的maven ...

  2. 使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(一)

    前言:原来一直使用MyEclipse,换工作后,新公司使用IDEA,初识IDEA发现,哇,它的快捷键可真多啊,但是一路用下来,觉得非常的好用,特别是利用Maven管理,那简直叫一个爽.当然笔者在使用过 ...

  3. 使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(二)

    前言:在使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(一)中已经介绍了如何对web基础环境进行搭建,这里主要演示,如何对spring环境进行搭建,然后 ...

  4. Spring MVC+Spring+Mybatis+MySQL(IDEA)入门框架搭建

    目录 Spring MVC+Spring+Mybatis+MySQL(IDEA)入门框架搭建 0.项目准备 1.数据持久层Mybatis+MySQL 1.1 MySQL数据准备 1.2 Mybatis ...

  5. 从零开始搭建一个react项目

    Nav logo 120 发现 关注 消息 4 搜索 从零开始搭建一个react项目 96 瘦人假噜噜 2017.04.23 23:29* 字数 6330 阅读 32892评论 31喜欢 36 项目地 ...

  6. Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合(注解及源码)

    Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合(注解及源码) 备注: 之前在Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合中 ...

  7. Spring MVC + Spring + Mybitis开发Java Web程序基础

    Spring MVC + Spring + Mybitis是除了SSH外的另外一种常见的web框架组合. Java web开发和普通的Java应用程序开发是不太一样的,下面是一个Java web开发在 ...

  8. 基于 Express 搭建一个node项目 - 起步

    一,如何基于 Express 搭建一个node项目 什么是Express 借用官方的介绍,Express是一个基于Node.js平台的极简.灵活的web应用开发框架,它提供了一系列强大的特性,帮助你创 ...

  9. 从零搭建一个SpringCloud项目之Feign搭建

    从零搭建一个SpringCloud项目之Feign搭建 工程简述 目的:实现trade服务通过feign调用user服务的功能.因为trade服务会用到user里的一些类和接口,所以抽出了其他服务需要 ...

随机推荐

  1. (10)ERStudio

     1.外键 https://jingyan.baidu.com/article/f79b7cb37e9d219144023ea6.html 第一个图标:Identifying Relationship ...

  2. HDU 6395 2018 Multi-University Training Contest 7 (快速幂+分块)

    原题地址 Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  3. 洛谷——P2660 zzc 种田

    P2660 zzc 种田 题目背景 可能以后 zzc就去种田了. 题目描述 田地是一个巨大的矩形,然而zzc 每次只能种一个正方形,而每种一个正方形时zzc所花的体力值是正方形的周长,种过的田不可以再 ...

  4. POJ 2441 Arrange the Bulls(状压DP)

    [题目链接] http://poj.org/problem?id=2441 [题目大意] 每个人有过个喜欢的篮球场地,但是一个场地只能给一个人, 问所有人都有自己喜欢的场地的方案数. [题解] 状态S ...

  5. IOS8设备连接XCODE6真机调试报错"Could not inspect the application package"

    每次真机调试都要运行2次才行,解决办法:把product name改成英文就行了.

  6. SONY的一款Win8平板

    今天看到了SONY新发布的一款x86的平板电脑: 铝合金的机身,分离的屏幕,非常漂亮.参数上还是很给力的,i5-4210/i7-4610的处理器,1920x1080的屏幕.4G的内存.9.9mm的厚度 ...

  7. 【安居客】资深PHP软件开发工程师

    工作职责: 1.网站项目的开发和维护: 2.负责技术部软件开发架构设计: 3.负责生产环境.测试环境和生产环境服务器运维和优化: 4.负责研究较前沿和复杂的技术运用: 岗位要求: 1.熟悉 PHP 程 ...

  8. C语言中<CR>是什么意思

    在文本处理中, CR, LF, CR/LF是不同操作系统上使用的换行符.Dos和windows采用回车+换行CR/LF表示下一行, 而UNIX/Linux采用换行符LF表示下一行,苹果机(MAC OS ...

  9. zookeeper 学习笔记3

    ZooKeeper 允许客户端向服务端注册一个 Watcher 监听, ZooKeeper 允许客户端向服务端注册一个 Watcher 监听, ZooKeeper 允许客户端向服务端注册一个 Watc ...

  10. 死磕 Fragment 的生命周期

    死磕 Fragment 的生命周期 本文原创,转载请注明出处.欢迎关注我的 简书 ,关注我的专题 Android Class 我会长期坚持为大家收录简书上高质量的 Android 相关博文.本篇文章已 ...