zoukankan      html  css  js  c++  java
  • 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>forceEncoding</param-name>
    33             <param-value>true</param-value>
    34         </init-param>
    35     </filter>
    36     <filter-mapping>
    37         <filter-name>characterEncodingFilter</filter-name>
    38         <url-pattern>/*</url-pattern>
    39     </filter-mapping>
    40 
    41 
    42     <!-- 可以把 POST 请求转为 DELETE 或 PUT 请求 -->
    43 
    44     <filter>
    45         <filter-name>HiddenHttpMethodFilter</filter-name>
    46         <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    47     </filter>
    48 
    49     <filter-mapping>
    50         <filter-name>HiddenHttpMethodFilter</filter-name>
    51         <url-pattern>/*</url-pattern>
    52     </filter-mapping>
    53 
    54 
    55 
    56     <!-- 配置 DispatcherServlet -->
    57     <servlet>
    58         <servlet-name>dispatcherServlet</servlet-name>
    59         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    60 
    61         <init-param>
    62             <param-name>contextConfigLocation</param-name>
    63             <param-value>classpath:springmvc.xml</param-value>
    64         </init-param>
    65 
    66         <load-on-startup>1</load-on-startup>
    67 
    68     </servlet>
    69 
    70     <servlet-mapping>
    71         <servlet-name>dispatcherServlet</servlet-name>
    72         <url-pattern>/</url-pattern>
    73     </servlet-mapping>
    74   
    75   
    76   
    77   
    78   
    79       
    80   <welcome-file-list>
    81     <welcome-file>index.jsp</welcome-file>
    82   </welcome-file-list>
    83 </web-app>

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

    <?xml version="1.0" encoding="UTF-8"?>
    <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"
        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-4.0.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    
        <!-- 配置自定扫描的包 -->
        <context:component-scan base-package="com.softjx" use-default-filters="false">
            <context:include-filter type="annotation" 
                expression="org.springframework.stereotype.Controller"/>
            </context:component-scan>
        
        
        <!-- 配置视图解析器: 如何把 handler 方法返回值解析为实际的物理视图 -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/views/"></property>
            <property name="suffix" value=".jsp"></property>
        </bean>
        
        
        <!-- 处理静态资源 -->
        <mvc:default-servlet-handler/>
        
        
        <!-- 默认配置方案。
        并提供了:数据绑定支持,@NumberFormatannotation支持,
        @DateTimeFormat支持,@Valid支持,读写XML的支持(JAXB),
        读写JSON的支持(Jackson)。
              后面,我们处理响应ajax请求时,就使用到了对json的支持。
         -->
        <mvc:annotation-driven></mvc:annotation-driven>
        
    
        
         
    </beans>

    3、在src目录下新建com.softjx.action包,在包里建Action类;

    注意:1)@Controller
       @RequestMapping("/student")

      2)每个方法:
       @RequestMapping("/studentAddInput")

      3) 类中注入
      @Autowired
      private StudentService studentService;//通过studentService调用Service里的方法调用Dao层

    4、在WEB-INF目录下创建views文件,用来放置所有.jsp文件,这个jsp文件名是作为Action中方法 return的值。;

    注意:1)在WEB-INF目录下的jsp页面只能通过程序来访问,外部访问不到。(安全)

         2)添加页面的jsp,要注意控件的属性名是javabean的属性名。 

  • 相关阅读:
    ptunnel-简易使用
    socat-简易使用
    ncat-相关参数用法
    通过iodine简单实现dns隧道技术
    HTB-靶机-Safe
    HTB-靶机-Rope
    【mysql子查询&组合查询 05】
    【mysql 库表操作 07】
    【mysql插入&修改&删除 06】
    【mysql 连接查询 04】
  • 原文地址:https://www.cnblogs.com/HawkFalcon/p/7799319.html
Copyright © 2011-2022 走看看