SSM组件

1.Spring Framework特性 IOC
依赖注入。
面向切面编程,包括spring的声明性事务管理。
Spring mvc web应用程序。
RESTful web service框架
JDBC, JPA, JMS的基础支持
1.1

org.springframework
spring-context
4.3.3.RELEASE

1.2 注解所需要 在 applicationContext.xml 中配置如下(Spring-IOC有关-->注解)


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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.xsd">



… …

2.Spring AOP
--2.1 .

org.springframework
spring-aspects
4.3.3.RELEASE

2.2
添加spring扫描
xmlns:aop="http://www.springframework.org/schema/aop"
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd






    
    
    
    
        
        
    

二、Spring-MVC
1.1 maven中引用Spring-MVC


org.springframework
spring-webmvc
4.3.3.RELEASE

1.2 创建springmvc配置文件
------创建:applicationServlet.xml
------默认配置文件:根目录dispatcher-servlet.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">







1.3 web.xml添加支持 (application.xml和selvelt.xml)

xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">


contextConfigLocation

classpath:spring/applicationContext.xml




org.springframework.web.context.ContextLoaderListener



springmvc
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath:spring/applicationServlet.xml

1



springmvc
*.do



encodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
UTF-8



encodingFilter
*.do

... ...

1.4在maven中引用SpringTest


org.springframework
spring-test
4.3.3.RELEASE

1.41 .测试用例添加注解 1
@RunWith(SpringJUnit4ClassRunner.class)
使用junit4进行测试
@ContextConfiguration
({"/spring/applicationContext.xml",
"/spring/applicationServlet.xml"})
加载配置文件,多个文件逗号分隔
@TransactionConfiguration(defaultRollback = false)
配置默认回滚

Spring-Web测试 1

模拟request
MockHttpServletRequest request
模拟response
MockHttpServletResponse response
执行前初始化request和response
request = new MockHttpServletRequest();
request.setCharacterEncoding("UTF-8");
response = new MockHttpServletResponse();
设置传入值
request.setParameter("username", "张三");
request.setParameter("password", "123456");

三.Mybatis

3.1

org.mybatis
mybatis
3.2.5


mysql
mysql-connector-java
5.1.40

3.2 mybatis的配置文件(mybatis-config.xml随便命名),包含了对MyBatis系统的核心设置。


PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">













    


3.3
通过mybatis配置文件(mybatis-config.xml),构建SqlSessionFactory对象
String resource = "mybatis-config.xml";
InputStream inputStream =
Resources.getResourceAsStream(resource);
sessionFactory =
new SqlSessionFactoryBuilder().build(inputStream);

3.4 employeeMapper.xml 中 sql Mapper


"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">


insert into user(id,name,nname,password,createtime,updatetime,
cost,money,usertypeid,phone)
values(#{id},#{name},#{nname},#{password},#{createtime},
#{updatetime},#{cost},#{money},#{usertypeid},#{phone})

... ...

你可能感兴趣的:(SSM组件)