$说明:

   ·Spring 5  + Mybatis 3.4.5 +SpringMVC 

   ·使用druid数据库

   ·使用log4j输出日志

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

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

Spring重点: 

  ·IOC(控制反转)

  ·DI(依赖注入)

  ·AOP (面向切面编程)

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context-3.2.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
  15. ">
  16.  
  17. <!-- 加载properties文件 -->
  18. <context:property-placeholder location="classpath:druid.properties" system-properties-mode="NEVER" />
  19. <!-- Spring 注解解析器 -->
  20. <context:annotation-config />
  21. <!-- 扫描 -->
  22. <context:component-scan base-package="com.xxx.*" />
  23.  
  24. <!-- druid配置 -->
  25. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
  26. <property name="url" value="${druid.url}"></property>
  27. <property name="driverClassName" value="${druid.driverClassName}"></property>
  28. <property name="username" value="${druid.username}"></property>
  29. <property name="password" value="${druid.password}"></property>
  30.  
  31. </bean>
  32.  
  33. <!-- mybatis文件配置,扫描所有mapper文件 -->
  34. <bean class="org.mybatis.spring.SqlSessionFactoryBean">
  35. <!-- 注入数据源 -->
  36. <property name="dataSource" ref="dataSource"></property>
  37. <!-- 配置mybatis全局文件 -->
  38. <property name="configLocation" value="classpath:mybatis.xml"></property> <!-- 加载mybatis文件 -->
  39. <property name="mapperLocations" value="classpath:mapper/*Mapping.xml"></property> <!-- 扫描所有mapper路径 -->
  40.  
  41. </bean>
  42.  
  43. <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
  44. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  45. <property name="basePackage" value="com.xxx.dao" />
  46. </bean>
  47.  
  48. </beans>

$ Mybatis 及其配置(部分)

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

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

Mybatis重点:

    ·全局配置文件

    ·Mybatis映射文件

    ·动态SQL

    ·一对多,多对一等关系

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

<部分代码可写入Spring中>

$SpringMVC 及其配置(部分)

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

SpringMVC重点

    ·控制器的使用Controller

    ·json

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

    ·拦截器

    ·核心:前端控制器(DispatcherServlet

    ·多视图控制

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:mvc="http://www.springframework.org/schema/mvc"
  7.  
  8. xsi:schemaLocation="http://www.springframework.org/schema/beans
  9. http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  10. http://www.springframework.org/schema/context
  11. http://www.springframework.org/schema/context/spring-context-3.2.xsd
  12. http://www.springframework.org/schema/aop
  13. http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  14. http://www.springframework.org/schema/mvc
  15. http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
  16. ">
  17.  
  18. <!-- <import resource="classpath:ApplicationContext.xml"/> -->
  19. <!-- 控制器扫描器 -->
  20. <context:component-scan base-package="com.xxx.controller"/>
  21.  
  22. <!--
  23. 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,
  24. 是spring MVC为@Controllers分发请求所必须的。
  25. 并提供了:数据绑定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,
  26. 读写XML的支持(JAXB),读写JSON的支持(Jackson)。
  27. -->
  28. <mvc:annotation-driven />
  29. <!-- 放行静态资源 -->
  30. <mvc:default-servlet-handler/>
  31.  
  32. <!-- 配置拦截器 -->
  33. <mvc:interceptors>
  34.  
  35. <mvc:interceptor>
  36. <!-- 拦截路径 -->
  37. <mvc:mapping path="/**"/>
  38. <!-- 放行 -->
  39. <mvc:exclude-mapping path="/User/login"/>
  40. <!-- 拦截类 -->
  41. <bean class="com.xxx.Interceptor.CheckLoginInterceptor"/>
  42. </mvc:interceptor>
  43.  
  44. </mvc:interceptors>
  45.  
  46. <!--
  47. 配置视图解析器
  48. -->
  49. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  50. <property name="prefix" value="/WEB-INF/views/"></property>
  51. <property name="suffix" value=".jsp"></property>
  52. </bean>
  53.  
  54. </beans>

$其他配置(部分)

  ·log4j日志配置:

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

  ·druid数据库配置:

  1. #druid基本配置
  2. druid.url=jdbc:mysql://127.0.0.1/springmvc?useUnicode=true&characterEncoding=utf8
  3. druid.driverClassName=com.mysql.jdbc.Driver
  4. druid.username=root
  5. 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. thinkphp遇到的小问题,js文件中U方法不被解析

    我想在js文件中写ajax, 写完发现异常, 本以为是js文件中不支持ajax 后来发现时地址解析错误. 也就是U方法在js文件中不被解析. 貌似thinkphp解析,tpl文件中的一些元素. js文 ...

  2. JavaWeb---总结(十九)Session机制

    一.术语session session,中文经常翻译为会话,其本来的含义是指有始有终的一系列动作/消息,比如打电话时从拿起电话拨号到挂断电话这中间的一系列过程可以称之为一个session.有时候我们可 ...

  3. Fragment的陷阱:概述

    现在主流的APP都会使用到Fragment,相信你也一定使用过,今天为大家介绍一下我曾经踏过的一个关于Fragment的坑. 以前做过的一个项目,Fragment嵌套高德地图,当再次进入Fragmen ...

  4. temp5

  5. accept巨坑

    在做node.js时, 我们要把一个资源发送回前端,需要用到以下一句: res.setHeader('Content-Type', mime ); mime,全称即Multipurpose Inter ...

  6. java5 CyclicBarrier同步工具

    CyclicBarrier是一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点(common barrier point).在涉及一组固定大小的线程的程序中,这些线程必须不时地互相等待,此 ...

  7. webmagic使用

    webmagic是Java语言用于爬虫的工具.官网地址:http://webmagic.io/,中文文档地址:http://webmagic.io/docs/zh/ 使用webmagic有3种配置需要 ...

  8. 配置环境是程序员的第一步 -- Windows 10 下 MySQL 安装

    MySQL 作为最典型的关系型数据库管理系统,由于其体积小.速度快.总体拥有成本低,尤其是其开放源码这一特点,一般中小型网站的开发都选择 MySQL 作为网站数据库.MySQL 社区版的功能也足够我们 ...

  9. ajax load事件

    ajax.load  使用ajax 来改变div元素文本. load( url [, data][, callback] ) load()方法的传递方式根据参数data来自动指定.如果没有参数传递,则 ...

  10. ubuntu 14 编译ARM g2o-20160424

    1. 安装eigen sudo apt-get install libeigen3-dev sudo apt-get install libsuitesparse-dev sudo apt-get i ...