$说明:

   ·Spring 5  + Mybatis 3.4.5 +SpringMVC 

   ·使用druid数据库

   ·使用log4j输出日志

$Spring 及其配置文件(部分)

Spring官方网站:http://spring.io/

Spring重点: 

  ·IOC(控制反转)

  ·DI(依赖注入)

  ·AOP (面向切面编程)

<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
"> <!-- 加载properties文件 -->
<context:property-placeholder location="classpath:druid.properties" system-properties-mode="NEVER" />
<!-- Spring 注解解析器 -->
<context:annotation-config />
<!-- 扫描 -->
<context:component-scan base-package="com.xxx.*" /> <!-- druid配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="url" value="${druid.url}"></property>
<property name="driverClassName" value="${druid.driverClassName}"></property>
<property name="username" value="${druid.username}"></property>
<property name="password" value="${druid.password}"></property> </bean> <!-- mybatis文件配置,扫描所有mapper文件 -->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 配置mybatis全局文件 -->
<property name="configLocation" value="classpath:mybatis.xml"></property> <!-- 加载mybatis文件 -->
<property name="mapperLocations" value="classpath:mapper/*Mapping.xml"></property> <!-- 扫描所有mapper路径 --> </bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xxx.dao" />
</bean> </beans>

$ Mybatis 及其配置(部分)

Mybatis官方网站:http://blog.mybatis.org/

Mybatis下载地址:https://github.com/mybatis/mybatis-3/releases

Mybatis重点:

    ·全局配置文件

    ·Mybatis映射文件

    ·动态SQL

    ·一对多,多对一等关系

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- mybatis的全局配置文件 -->
<typeAliases> <typeAlias type="com.xxx.pojo.User" alias="User" />
</typeAliases> </configuration>

<部分代码可写入Spring中>

$SpringMVC 及其配置(部分)

SpringMVC无缝接入Spring ,可在Spring官网中及其文档中查看

SpringMVC重点

    ·控制器的使用Controller

    ·json

    ·放行静态资源:*.js  *.css *.jpg等

    ·拦截器

    ·核心:前端控制器(DispatcherServlet

    ·多视图控制

<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
"> <!-- <import resource="classpath:ApplicationContext.xml"/> -->
<!-- 控制器扫描器 -->
<context:component-scan base-package="com.xxx.controller"/> <!--
会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,
是spring MVC为@Controllers分发请求所必须的。
并提供了:数据绑定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,
读写XML的支持(JAXB),读写JSON的支持(Jackson)。
-->
<mvc:annotation-driven />
<!-- 放行静态资源 -->
<mvc:default-servlet-handler/> <!-- 配置拦截器 -->
<mvc:interceptors> <mvc:interceptor>
<!-- 拦截路径 -->
<mvc:mapping path="/**"/>
<!-- 放行 -->
<mvc:exclude-mapping path="/User/login"/>
<!-- 拦截类 -->
<bean class="com.xxx.Interceptor.CheckLoginInterceptor"/>
</mvc:interceptor> </mvc:interceptors> <!--
配置视图解析器
-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean> </beans>

$其他配置(部分)

  ·log4j日志配置:

#日志的基本设置
# 设置日志的全局配置,级别越小显示的越详细 trace<debug<info<warn<error<fatal
log4j.rootLogger=debug, stdout
# log4j.logger.加需要输出的包的路径 并设置日志级别
log4j.logger.com.Mapping=TRACE
# Console output... 将文件输出达到某个位置 ConsoleAppender 输出到控制台
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

  ·druid数据库配置:

#druid基本配置
druid.url=jdbc:mysql://127.0.0.1/springmvc?useUnicode=true&characterEncoding=utf8
druid.driverClassName=com.mysql.jdbc.Driver
druid.username=root
druid.password=082999

$注意:

    ·部分包名如: com.xxx.Controller      是自用包名。请读者详细查看后记得修改。 不然会报配置文件无效相关的错误。

SSM项目配置文件及其各项使用的更多相关文章

  1. SSM项目配置文件DEMO

    SSM相关配置文件 <spring-mvc.xml>文件 <?xml version="1.0" encoding="UTF-8"?> ...

  2. SSH和SSM项目的打通各个页面的方式

    SSH项目: 这里采用的action的形式: 即在表现层为页面在action中配置一个返回值,然后在Struts.xml的配置文件中进行配置. SSM项目中,SpringMVC中利用注解来配置每个页面 ...

  3. SSH项目与SSM项目的进入首页的方法

    SSH项目中: jsp页面一般都是存放在WEB-INF下面的目录下,这样我们就不能直接访问到这些jsp页面了,保证了页面的安全性. 在struts的管理中,是利用action来实现页面的跳转,进入in ...

  4. 使用idea建立gradle+SSM项目

    目录: 一.创建一个gradle项目   二 .在gradle中创建SSM项目 一 .创建一个gradle项目 第一步: 第二步:选择gradle,并选中web,然后点击Next进入下一步 第三步:此 ...

  5. SSM项目整合基本步骤

    SSM项目整合 1.基本概念 1.1.Spring Spring 是一个开源框架, Spring 是于 2003  年兴起的一个轻量级的 Java  开发框架,由 Rod Johnson  在其著作  ...

  6. SSM框架搭建——我的第一个SSM项目

    转载自:http://blog.csdn.net/tmaskboy/article/details/51464791 作者使用MyEclipse 2014版本 本博客所编写程序源码为: http:// ...

  7. Maven 搭建 SSM 项目 (oracle)

    简单谈一下maven搭建 ssm 项目 (使用数据库oracle,比 mysql 难,所以这里谈一下) 在创建maven 的web项目时,常常会缺了main/java , main/test 两个文件 ...

  8. 搭建ssm项目框架

    [声明]转载注明链接,源码联系公众号:aandb7获取 [此处组织名groupId:com.dayuanit,可替换公司域名:项目名artifactid:...] 此处第二个配置文件选择maven安装 ...

  9. SSM项目整合Quartz

    一.背景 SSM项目中要用到定时器,初期使用Timer,后来用spring 的schedule,都比较简单,所以功能比较单一而且他们不能动态的配置时间.后来就研究quartz,准备整合到项目中.Qua ...

随机推荐

  1. Java-Maven-Runoob:Maven Eclipse

    ylbtech-Java-Maven-Runoob:Maven Eclipse 1.返回顶部 1. Maven Eclipse Eclipse 提供了一个很好的插件 m2eclipse ,该插件能将 ...

  2. json、pickle\shelve模块(超级好用~!)讲解

    json.pickle模块讲解 见我前面的文章:http://www.cnblogs.com/itfat/p/7456054.html shelve模块讲解(超级好用~!) json和pickle的模 ...

  3. python学习(十七) 扩展python

    c, c++, java比python快几个数量级. 17.1 考虑哪个更重要 开发速度还是运行速度更重要. 17.2 非常简单的途径:Jython和IronPython Jython可以直接访问JA ...

  4. Venom的简单使用

    工具地址:https://github.com/r00t-3xp10it/venom 打开到venom目录,输入./venom.sh 打开程序 按回车键继续 这里有很多的模块,要用哪个模块就输入它的编 ...

  5. js中的Generators函数

    js中的Generators函数 generator一般操作 generator函数的作用就是函数体分段执行,yield表示分隔点 function *test() { console.log(1); ...

  6. Python Twisted系列教程6:抽象地利用Twisted

    作者:dave@http://krondo.com/and-then-we-took-it-higher/  译者:杨晓伟(采用意译) 你可以从这里从头开始阅读这个系列. 打造可以复用的诗歌下载客户端 ...

  7. 代理模式 静态代理、JDK动态代理、Cglib动态代理

    1 代理模式 使用代理模式时必须让代理类和被代理类实现相同的接口: 客户端通过代理类对象来调用被代理对象方法时,代理类对象会将所有方法的调用分派到被代理对象上进行反射执行: 在分派的过程中还可以添加前 ...

  8. 面试题--CVTE

    2.HashMap和HashSet的实现原理,hashset 和hashMap区别 HashSet底层就是HashMap实现的, *HashMap* *HashSet* HashMap实现了Map接口 ...

  9. CMake 自定义编译选项

    自定义编译选项 CMake 允许为项目增加编译选项,从而可以根据用户的环境和需求选择最合适的编译方案. 例如,可以将 MathFunctions 库设为一个可选库,如果该选项为 ON ,就使用该库定义 ...

  10. Ubuntu16.04 ARM 编译 编译器版本和unordered_map map问题

    源文件内使用unordered_map时候,例如如下demo #include <unordered_map> void foo(const std::unordered_map<i ...