设为首页 加入收藏

TOP

SSM框架的搭建(一)
2019-09-17 18:55:08 】 浏览:57
Tags:SSM 框架 搭建

第一阶段:

1、用PowerDesign建数据模型,并导出SQL文件;

2、将SQL文件导入到MySQL客户端,建立表格;

  MySQL数据远程访问:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

如果是固定IP:grant all privileges on *.* to 'root'@'192.168.41.100'identified by '123456' with grant option;

//推送设置到内存或重启服务器也行
mysql>FLUSH PRIVILEGES

3、使用MyBatis框架,搭建DAO层:----------------------------Mybatis----------------------

  1)数据库连接的信息:驱动类、连接地址、用户名、密码
<jdbcConnection driverClass="com.mysql.jdbc.Driver"        connectionURL="jdbc:mysql://192.168.41.100:3306/testtest" userId="root"    password="123456"></jdbcConnection>


  2)targetPackage="com.softjx.model"

  3)把表名与类名对应
<table schema="testtest" tableName="school" domainObjectName="School"></table>


  4)运行GeneratorSqlmap.java生成dao和model

第二阶段:

1、在MyEclipse上新建一个Web项目,并导入ssm所需的jar包,放在WEB-INF/lib目录下;

2、将第一阶段通过Mybatis框架生成的model和dao复制到当前项目;----------------------------Dao层----------------------

3、搭建Service层:建com.softjx.service与com.softjx,service,impl包;----------------------------spring层----------------------

4、将需要相关的配置文件(mybatisconfig.xml,dbconfig.properties,applicationContext.xml,log4j.properties)放到src目录下;

  1)修改dbconfig.properties文件,ip,数据库,用户名,密码

  2)修改applicationContext.xml中的包名,目录名

5、在com.softjx.service包中写接口,在com.softjx.service.impl写接口的实现。
  注意:com.softjx.service.impl写接口的实现,
  @Service("studentService")
  @Transactional

  
  类中注入
  @Autowired
  private StudentMapper studentMapper;

7.单元测试:
  要注意mysql数据库中主键要自增,这一步要我们去mysql中设置。
  studentService = (StudentService) context.getBean("studentService");
  这个"studentService"是从@Service("studentService")

 

第三阶段:

1、修改WebRoot目录下的web.xml如下:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="2.5" 
 3     xmlns="http://java.sun.com/xml/ns/javaee" 
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 5     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 6     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 7   <display-name></display-name>
 8   
 9   
10   
11     <!-- 配置启动 Spring IOC 容器的 Listener,启动spring容器 -->
12     <context-param>
13         <param-name>contextConfigLocation</param-name>
14         <param-value>classpath:applicationContext.xml</param-value>
15     </context-param>
16 
17     <listener>
18         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
19     </listener>
20 
21 
22     <!-- 表单提交controller获得中文参数后乱码解决方案 注意: jsp页面编码设置为UTF-8 form表单提交方式为必须为post,get方式下面spring编码过滤器不起效果 -->
23 
24     <filter>
25         <filter-name>characterEncodingFilter</filter-name>
26         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
27         <init-param>
28             <param-name>encoding</param-name>
29             <param-value>UTF-8</param-value>
30         </init-param>
31         <init-param>
32             <param-name>forceEncodi
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇数据分区------《Designing Data-.. 下一篇docker~环境变量到底怎么用

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目