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如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name> <!-- 配置启动 Spring IOC 容器的 Listener,启动spring容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 表单提交controller获得中文参数后乱码解决方案 注意: jsp页面编码设置为UTF-8 form表单提交方式为必须为post,get方式下面spring编码过滤器不起效果 --> <filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 可以把 POST 请求转为 DELETE 或 PUT 请求 --> <filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter> <filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 配置 DispatcherServlet -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</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的属性名。
SSM框架的搭建的更多相关文章
- ssm框架的搭建实现CRUD的操作
最近在开发公司的一个系统,系统的框架是用ssm的框架搭建的,当然和这次写博客的不一样,它拥有很多的配置文件,企业级的开发所需要的配置文件是非常繁琐的,今天记录一下一个简单的SSM框架的搭建和实现一个C ...
- SSM框架手动搭建
SSM框架手动搭建 创建web项目 IDEA创建Maven项目 [File]-->[new]-->[project..] 将项目变为web项目 [File]-->[Project S ...
- Spring+SpringMVC+Mybatis(SSM)框架集成搭建
Spring+SpringMVC+Mybatis框架集成搭建教程 一.背景 最近有很多同学由于没有过SSM(Spring+SpringMvc+Mybatis , 以下简称SSM)框架的搭建的经历,所以 ...
- SSM框架整合搭建教程
自己配置了一个SSM框架,打算做个小网站,这里把SSM的配置流程详细的写了出来,方便很少接触这个框架的朋友使用,文中各个资源均免费提供! 一. 创建web项目(eclipse) File-->n ...
- SSM框架——整合搭建流程
1.首先创建maven工程,使用哪种方式进行创建都可以,可以参考博主之前的文章: <两种方式创建Maven项目[方式二]><两种方式创建Maven项目[方式一]> 2.先看看搭 ...
- SSM框架理解搭建(虽然是网上拼的,但是实际按照搭建是可以的)——
SpringSpring就像是整个项目中装配bean的大工厂,在配置文件中可以指定使用特定的参数去调用实体类的构造方法来实例化对象.Spring的核心思想是IoC(控制反转),即不再需要程序员去显式地 ...
- SSM框架的搭建与测试
关于框架的搭建无非就是 框架所依赖的jar包,然后就是关于各个框架的配置文件: 下面我们来看下不同层的依赖的jar包以及各个配置文件: 首先pojo这一层只需要依赖parent聚合工程 mapper层 ...
- ssm框架的搭建流程
1.新建一个Maven project (1)选中create a simple project,自动配置必要的文件 (2)Packaging选择war类型.jar和war的区别就是一个是普通的jav ...
- Spring mybatis 之-ssm框架环境搭建(方案一)
SSM框架- S-Spring S-Spring mvc M-mybatis 就需要以下几个配置文件,放在resources文件夹下面: db.properties 放的是数据库连接池的配置文件, ...
随机推荐
- Windows下Mysql5.7开启binlog步骤及注意事项
1.查看是否开启了binlog:show binary logs; 默认情况下是不开启的. 2.开启binlog:修改mysql的配置文件my.ini.添加如下配置: 该文件默认不允许修改,需要右键“ ...
- JS难点--面向对象(封装)
我觉得js的难点之一就是面向对象编程. 面向对象 它是一种编程思想,它在写法上比面向过程相对来说复杂一些: 以下是我学习中关于面向对象的知识点总结: 1.什么是对象 从广义上说,"一切皆 ...
- Asp.net MVC4高级编程学习笔记-模型学习第四课基架与模型绑定20171027
MVC模型 一.构建基架. MVC中的基架可以为应用程序提供CURD各种功能生成所需要的样板代码.在添加控制器的时候可以选择相应的模板以及实体对象来生成相应的模板代码. 首先定义一个模型类如下所示: ...
- LeetCode 111. Minimum Depth of Binary Tree (二叉树最小的深度)
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- 10大H5前端框架,让你开发不愁
和app.run(),config是你设置任何的provider的阶段,从而使应用可以使用正确的服务,需要注意的是在 ...
- 通过对DAO层的封装减少数据库操作的代码量
在学框架之前,写项目时总是要花大量的时间去写数据库操作层代码,这样会大大降低我们的效率,为了解决这个问题,我花了两天时间利用反射机制和泛型将DAO层进行了封装,这样我们只需要写sql语句,不需要再写 ...
- Max Sum Plus Plus
A - Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- Unity 游戏框架搭建 (七) 减少加班利器-QApp类
本来这周想介绍一些框架中自认为比较好用的小工具的,但是发现很多小工具都依赖一个类----App. App类的职责: 1.接收Unity的生命周期事件. 2.做为游戏的入口. 3.一些框架级别的组件初始 ...
- js跨域问题解决方案
跨域:当协议.域名.端口号任何一个不相同时,叫称为跨域. HTML5 CORS(cross-origin-resource-sharing)跨域资源共享: 原理:当需要访问跨域的资源时,可以通 ...