技术选型:

一.项目搭建:

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. [BZOJ2654]tree 最小生成树+贪心

    2654: tree Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 2435  Solved: 1011[Submit][Status][Discus ...

  2. Fiddler在fiddler option设置还是抓不了HTTPS包解决办法

    1:请在“运行”,即下面这个地方输入certmgr.msc并回车,打开证书管理. 打开后,请点击操作--查找证书,如下所示: 然后输入“fiddler”查找所有相关证书,如下所示: 可以看到,我们找到 ...

  3. Count Primes -- LeetCodes (primality test)

    Description: Count the number of prime numbers less than a non-negative number, n. 思路:这题第一种思路是写一个is_ ...

  4. jQuery滑动方法

    jQuery 滑动方法 通过 jQuery,您可以在元素上创建滑动效果. jQuery 拥有以下滑动方法: slideDown() slideUp() slideToggle() jQuery sli ...

  5. SONY的一款Win8平板

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

  6. Creating and Flashing UBIFS with MTD Utils

    转:http://wiki.atlas-embedded.com/index.php?title=Creating_and_Flashing_UBIFS_with_MTD_Utils Contents ...

  7. log4j教程 1、概述

    log4j是一个用Java编写的可靠,快速和灵活的日志框架(API),它在Apache软件许可下发布.    Log4j已经被移植到了C,C++,C#,Perl,Python和Ruby等语言中.   ...

  8. Python开发easy忽略的问题

    这篇文章主要介绍了Python程序猿代码编写时应该避免的17个"坑",也能够说成Python程序猿代码编写时应该避免的17个问题,须要的朋友能够參考下 一.不要使用可变对象作为函数 ...

  9. mysql二进制安装及基础操作

    mysql二进制安装及基础操作 环境说明: 系统版本    CentOS 6.9 x86_64 软件版本    mysql-5.6.36-linux-glibc2.5-x86_64 1.安装 采用二进 ...

  10. iptables 使用场景

    25 Most Frequently Used Linux IPTables Rules Examples by RAMESH NATARAJAN on JUNE 14, 2011 At a firs ...