SSM整合(无Maven)

1、开发环境

IDE: Eclipse Mars2
Jdk: 1.8
数据库: MySQL

2、创建数据库

数据库sql文件位置如下图:
数据库文件
创建crm数据库,执行sql语句

DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `id` int(11) DEFAULT NULL,
  `username` varchar(60) DEFAULT NULL,
  `password` varchar(60) DEFAULT NULL,
  `name` varchar(60) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  `gender` int(11) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `updated` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `user` VALUES ('1', 'zhangsan', '123456', '张三', '2019-06-10', '1', '2019-06-10 10:03:52', '2019-06-10 10:03:55');
INSERT INTO `user` VALUES ('2', 'lisi', '123456', '李四', '2019-06-03', '0', '2019-06-09 10:04:17', '2019-06-12 10:04:21');

3、工程搭建

工程使用Springmvc、spring、mybatis框架整合完成。

3.1.需要的jar包

1.spring(包括springmvc)
2.mybatis
3.mybatis-spring整合包
4.数据库驱动
5.第三方连接池。
6.Json依赖包Jackson
jar包位置如下图:
在这里插入图片描述

3.2.整合思路

Dao层:
1、SqlMapConfig.xml,空文件即可,但是需要文件头。
2、applicationContext-dao.xml
1、数据库连接Druid
2、SqlSessionFactory对象,需要spring和mybatis整合包下的。
3、配置mapper文件扫描器。Mapper动态代理开发 增强版
Service层:
1、applicationContext-service.xml包扫描器,扫描@service注解的类。
2、applicationContext-trans.xml配置事务。
Controller层:
1、springMvc.xml
1、包扫描器,扫描@Controller注解的类。
2、配置注解驱动
3、配置视图解析器
Web.xml文件:
1、配置spring监听器
2、配置前端控制器。

3.3.创建工程

创建动态web工程,步骤如下图:
在这里插入图片描述
创建ssm,如下图:
在这里插入图片描述

3.4.加入jar包

加入前面照片中的jar包

3.5.加入配置文件

创建config资源文件夹,在里面创建mybatis和spring文件夹

3.5.1.SqlMapConfig.xml

空文件即可

<?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>
	<!--别名-->
	<typeAliases>
		<package name="com.pojo"/>
	</typeAliases>
</configuration>  

3.5.2.applicationContext-dao.xml

需要配置:
加载properties文件,数据源,SqlSessionFactory,Mapper扫描

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://www.springframework.org/schema/beans"
	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-4.1.xsd 
	http://www.springframework.org/schema/context 
	http://www.springframework.org/schema/context/spring-context-4.1.xsd 
	http://www.springframework.org/schema/aop 
	http://www.springframework.org
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值