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)数据库连接的信息:驱动类、连接地址、用户名、密码

  2)targetPackage=”com.softjx.model”

  3)把表名与类名对应

  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 
 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     
12     <context-param>
13         <param-name>contextConfigLocationparam-name>
14         <param-value>classpath:applicationContext.xmlparam-value>
15     context-param>
16 
17     <listener>
18         <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
19     listener>
20 
21 
22     
23 
24     <filter>
25         <filter-name>characterEncodingFilterfilter-name>
26         <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
27         <init-param>
28             <param-name>encodingparam-name>
29             <param-value>UTF-8param-value>
30         init-param>
31         <init-param>
32             <param-name>forceEncodingparam-name>
33             <param-value>trueparam-value>
34         init-param>
35     filter>
36     <filter-mapping>
37         <filter-name>characterEncodingFilterfilter-name>
38         <url-pattern>/*url-pattern>
39     filter-mapping>
40 
41 
42     
43 
44     <filter>
45         <filter-name>HiddenHttpMethodFilterfilter-name>
46         <filter-class>org.springframework.web.filter.HiddenHttpMethodFilterfilter-class>
47     filter>
48 
49     <filter-mapping>
50         <filter-name>HiddenHttpMethodFilterfilter-name>
51         <url-pattern>/*url-pattern>
52     filter-mapping>
53 
54 
55 
56     
57     <servlet>
58         <servlet-name>dispatcherServletservlet-name>
59         <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
60 
61         <init-param>
62             <param-name>contextConfigLocationparam-name>
63             <param-value>classpath:springmvc.xmlparam-value>
64         init-param>
65 
66         <load-on-startup>1load-on-startup>
67 
68     servlet>
69 
70     <servlet-mapping>
71         <servlet-name>dispatcherServletservlet-name>
72         <url-pattern>/url-pattern>
73     servlet-mapping>
74   
75   
76   
77   
78   
79       
80   <welcome-file-list>
81     <welcome-file>index.jspwelcome-file>
82   welcome-file-list>
83 web-app>

2、在src目录下建立springmvc.xml文件,文件内容如下:———-SpringMVC层—————-


<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:mvc="http://www.springframework.org/schema/mvc"
    

你可能感兴趣的:(java,框架开发,ssm框架)