技术选型:

一.项目搭建:

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. maven 在 mac中的配置

    思前想后,还是在mac中把maven配置一下吧. 1.下载安装包,由于公司用的版本比较低,考虑到兼容性,建议用低版本的.我用3.0.5 下载地址:http://archive.apache.org/d ...

  2. Vue.js之父子组件

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. Openstack ceilometer

    https://www.cnblogs.com/liguangsunls/p/6879879.html

  4. aliyun

    阿里云启动不了网站 1  将网站的目录属性-安全中加入IUSER_计算机名字的访问权限     和  加入NER SERVICE的访问权限 2 IIS打开网站属性--目录--执行权限改为顺脚本 3  ...

  5. 每天一个Linux命令(10)cp命令

    cp命令用来将一个或多个源文件或者目录复制到指定的目的文件或目录.它可以将单个源文件复制成一个指定文件名的具体的文件或一个已经存在的目录下.cp命令还支持同时复制多个文件,当一次复制多个文件时,目标文 ...

  6. ASP.net MVC 基于角色的权限控制系统的实现

    一.引言 我们都知道ASP.net mvc权限控制都是实现AuthorizeAttribute类的OnAuthorization方法. 下面是最常见的实现方式: public class Custom ...

  7. Python学习笔记——模块

    使用模块 python中包的组织方式是模块,一个使用其它模块的例子如下: # Filename: using_sys.py import sys print 'The command line arg ...

  8. 设计模式之桥接模式(php实现)

    github地址:https://github.com/ZQCard/design_pattern /** * 桥接模式 * 优点: * 1.分离抽象接口及其实现部分.提高了比继承更好的解决方案. * ...

  9. 150725培训心得(vector)

    vector(不定长数组) 在C语言中,数组定义必须给定长度.可是有的时候太浪费空间,能够利用STL中vector函数来解决问题. 1 基本操作 (1)头文件#include<vector> ...

  10. solr 常用命令

    1.启动和关闭 a.启动和重启 启动和重启命令有很多选项让你运行在SolrCloud模式,使用示例配置,以hostname为开头或者非默认端口,指向本地ZooKeeper. bin/solr star ...