SSM框架完整开发流程
----------------第一阶段--------------
1.数据库建模
2.生成sql语句
3.在mysq客户端使用命令方式执行sql脚本,生成数据库
4.允许远程访问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
5.使用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>
<table schema="testtest" tableName="student" domainObjectName="Student"></table>
6.运行GeneratorSqlmap
-------------------------第二阶段--------------------------
1.新建一个WEB项目
2.导入ssm所需要所有jar包,把所有jar放到WEB-INF/lib目录下
3.把mybatis生成dao,model复制到当前项目
4.建com.softjx.service,com.softjx.service.impl
5.需要相关的配置文件(mybatisconfig.xml,dbconfig.properties,applicationContext.xml,log4j.properties)
1 )修改dbconfig.properties文件,ip,数据库,用户名,密码
2)修改applicationContext.xml中的包名,目录名
6.在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.web.xml配置文件要修改。
2.在类路径下src目录新建springmvc.xml
3.建com.softjx.action包
4.在com.softjx.action编写action
要注意:
1)@Controller
@RequestMapping("/student")
2)
@RequestMapping("/studentAddInput")
类中注入
@Autowired
private StudentService studentService;
5.在WEB-INF目录下建views文件夹
6.在views文件夹建jsp文件,这个jsp文件名是作为action中方法 return的值。
7.添加页面的jsp,要注意控件的属性名是javabean的属性名。
8.在WEB-INF目录下jsp是不能在页面上直接访问,要通过程序访问。
-----------------------第四阶段---------------------------
1.dao层(mybatis)
2.service层(spring)
3.单元测试
4.action(springmvc)
5.jsp html,htm (界面)
1 )查询所有数据
2)单条件查询
3)多条件查询
4)分页查询
-------------------
5) 单条件分页查询
6)多添加分页查询
-------------------
7) 修改(先查询单个实体)
8)删除(先查询单个实体)
-----------------------第五阶段---------------------------
1)文件上传
a.要导入commons-fileupload-1.2.1.jar,commons-io-2.0.jar这两个包
b. <!-- 配置 MultipartResolver 上传文件-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
<property name="maxUploadSize" value="10240000"></property>
</bean>
c.在WEB-INF同一层目录中建一个upload目录
d.上传文件的jsp界面
<form action="student/checkFileUpload" method="POST" enctype="multipart/form-data">
文件: <input type="file" name="file"/>
描述: <input type="text" name="desc"/>
<input type="submit" value="上传数据"/>
</form>
e.编写上传文件的action
2)文件下载
a.在WEB-INF同一层目录中建一个upload目录
b.下载的url:
<a href="student/fileDownload?filename=hibernate1.jpg">通过 文件流 的方式下载文件hibernate1.jpg</a>
c.编写下载文件的action
-----------------------第六阶段---------------------------
1.把数据库中数据导出到excel
1)导入包poi-3.2-FINAL-20081019.jar
2)在action中写代码
3)注意excel表格中的各种格式
-----------------------第七阶段(两个表查询,有关系)---------------------------
一.根据条件查询
1).掌握多表查询
select a.*,b.* from student a,school b where a.t_sid=b.t_id
select a.t_id,a.t_name,a.t_age,a.t_enterdate,b.t_name as t_name1 from student a,school b where a.t_sid=b.t_id
select a.t_id,a.t_name,a.t_age,a.t_enterdate,b.t_name as t_name1 from student a LEFT JOIN school b on a.t_sid=b.t_id
2).设计实体类中要关联类,在Student类中有School类的引用。
private School school;
public School getSchool() {
return school;
}
public void setSchool(School school) {
this.school = school;
}
3)在StudentMapper.xml编写sql语句
<!-- 返回多表查询的字段名 -->
<resultMap id="WithSchoolResultMap" type="com.softjx.model.Student" >
<id column="t_id" property="tId" jdbcType="INTEGER" />
<result column="t_name" property="tName" jdbcType="VARCHAR" />
<result column="t_age" property="tAge" jdbcType="INTEGER" />
<result column="t_enterdate" property="tEnterdate" jdbcType="TIMESTAMP" />
<result column="t_sid" property="tSid" jdbcType="INTEGER" />
<!-- 指定联合查询出的学校字段-->
<association property="school" javaType="com.softjx.model.School">
<id column="t_id1" property="tId"/>
<result column="t_name1" property="tName"/>
</association>
</resultMap>
<!-- 多表查询的字段名 -->
<sql id="Student_School_Column_List">
a.t_id, a.t_name, a.t_age, a.t_enterdate, a.t_sid,b.t_id as t_id1,b.t_name as t_name1
</sql>
<!-- 查询学生同时带学校信息 -->
<select id="selectByExampleWithSchool" resultMap="WithSchoolResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Student_School_Column_List" />
FROM student a
left join school b on a.t_sid=b.t_id
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
4).在dao中编写一个接口
//多表查询
List<Student> selectByExampleWithSchool(StudentExample example);
5).在service层编写接口与接口的实现
//多表查询
public List<Student> getStudentWithSchool(StudentExample studentExample);
public List<Student> getStudentWithSchool(StudentExample studentExample) {
return studentMapper.selectByExampleWithSchool(studentExample);
}
6)编写单元测试多表查询。
二.根据主键查询两个表
1) .
select a.t_id,a.t_name,a.t_age,a.t_enterdate,b.t_name as t_name1 from student a LEFT JOIN school b on a.t_sid=b.t_id where a.t_id=3
2).设计实体类中要关联类,在Student类中有School类的引用。
private School school;
public School getSchool() {
return school;
}
public void setSchool(School school) {
this.school = school;
}
3).在StudentMapper.xml编写sql语句
<!-- 返回多表查询的字段名 -->
<resultMap id="WithSchoolResultMap" type="com.softjx.model.Student" >
<id column="t_id" property="tId" jdbcType="INTEGER" />
<result column="t_name" property="tName" jdbcType="VARCHAR" />
<result column="t_age" property="tAge" jdbcType="INTEGER" />
<result column="t_enterdate" property="tEnterdate" jdbcType="TIMESTAMP" />
<result column="t_sid" property="tSid" jdbcType="INTEGER" />
<!-- 指定联合查询出的学校字段-->
<association property="school" javaType="com.softjx.model.School">
<id column="t_id1" property="tId"/>
<result column="t_name1" property="tName"/>
</association>
</resultMap>
<!-- 多表查询的字段名 -->
<sql id="Student_School_Column_List">
a.t_id, a.t_name, a.t_age, a.t_enterdate, a.t_sid,b.t_id as t_id1,b.t_name as t_name1
</sql>
<!-- 主键查询多表数据 -->
<select id="selectByPrimaryKeyWithSchool" resultMap="WithSchoolResultMap">
select
<include refid="Student_School_Column_List" />
FROM student a
left join school b on a.t_sid=b.t_id
where a.t_id = #{tId,jdbcType=INTEGER}
</select>
4).在dao中编写一个接口
Student selectByPrimaryKeyWithSchool(Integer tId);
5)在service层编写接口与接口的实现
public Student selectByPrimaryKeyWithSchool(Integer tId);
public Student selectByPrimaryKeyWithSchool(Integer tId) {
return studentMapper.selectByPrimaryKeyWithSchool(tId);
}
6)编写单元测试主键查询多个表中的数据。
------------------------------第八阶段springmvc使用拦截器---------------------
1.编写一个类继承HandlerInterceptor接口
在这个方法中实现业务
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object arg2) throws Exception {
System.out.println("第一个拦截器中的 preHandle方法被调用");
//1).从sesion中获取用户对象
//2).用当前用户所拥有的菜单url是否包含当前请求
}
2.配置springmvc的配置文件,添加拦截器
<mvc:interceptors>
<!--局部拦截器配置, 配置拦截器不作用的路径 ,要先配置<mvc:mapping path="/**" /> ,否则报错,不能少这个-->
<mvc:interceptor>
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/login/**"/>
<bean class="com.softjx.interceptor.ActionMethodInterceptor"></bean>
</mvc:interceptor>
3.登录时要保存当前用户对象到session
--------------------第九阶段 mybatis使用三表或者更多表查询--------------------
一.不使用数据库中的多表查询(使用用户多,十万,百万,千万,亿)
思想:
1.查询学生表
2.根据学生所有学校的id,查询对应学校名称
3.根据学校的区域id查询区域名
4.用查询的数据组装一个vo(view object)(javabean), 这个javabean只是显示在界面上的。
5.多个vo组装ArrayList中
6.显示ArrayList中的数据
如何做:
1.要把以前写的两个表的关联xml复制到一个地方,使用生成框架,生成后添加方法到dao中和xml中
2.新建一个javabean ,是一个vo
3.在service中编写一个方法,返回一个vo的集合类型。(这个里面要仔细看下)
4.测试一下这个方法。
二.使用数据库中的多表查询(使用用户一般几百,几千,几万)
SELECT a.*,b.*,c.* from student a,school b,areatable c where a.t_sid=b.t_id and b.t_area_id=c.t_id
SELECT a.t_id,a.t_name,a.t_age,a.t_enterdate,b.t_name as t_name1,c.area from student a,school b,areatable c where a.t_sid=b.t_id and b.t_area_id=c.t_id
思想:
1.使用sql语句
2.在StudentMapper接口中写方法
3.要在StudentMapper.xml中写sql语句实现
1)编写一个<resultMap>
2)编写接口中方法的实现
<resultMap id="BaseSqlResultMap" type="com.softjx.vo.StudentSchoolAreaVo" >
<id column="t_id" property="id" jdbcType="BIGINT" />
<result column="t_name" property="name" jdbcType="VARCHAR" />
<result column="t_age" property="age" jdbcType="TINYINT" />
<result column="t_enterdate" property="enterDate" jdbcType="DATE" />
<result column="t_name1" property="schoolName" jdbcType="VARCHAR" />
<result column="area" property="areaName" jdbcType="VARCHAR" />
</resultMap>
<select id="getStudentSchoolAreaSqlVo" resultMap="BaseSqlResultMap">
SELECT a.t_id,a.t_name,a.t_age,a.t_enterdate,b.t_name as t_name1,c.area from student a,school b,areatable c
where a.t_sid=b.t_id and b.t_area_id=c.t_id
</select>
4.在service中编写接口方法与实现。
--------------------第十阶段 使用jquery中的ajax技术--------------------
1.需要一个jquery的类库.js 放到static目录下,要注意拦截器放行。
2.jsp中导入js类库。
<script type="text/javascript" src="static/js/jquery-1.8.3.js"></script>
jquery的环境搭建完毕。
3.在springmvc中开发一个业务方法。
@ResponseBody//返回的数据是json数据
@RequestMapping("/studentName")
public List<Student> getStudentName(Map<String, Object> map, Student student) {
StudentExample studentExample = new StudentExample();
Criteria criteria = studentExample.createCriteria();
if (student.gettName() != null && !student.gettName().trim().equals(""))
criteria.andTNameEqualTo(student.gettName());
List<Student> students = studentService.getStudents(studentExample);
return students;
}
注意:1)返回值是对象类型或者是基本类型,2)@ResponseBody//返回的数据是json数据
4.在jsp页面上控制我们操作的构件,使用jquery的选择器,选中此对象。
5.编写ajax代码
<script type="text/javascript">
$(document).ready(function(){
$("#nameid").blur(function(){
//真实场景下的ajax调用
$.ajax(
{
url: "student/studentName1",
cache: false,
type: "GET",
dataType:"json",
async: true,
data: {tName:$("#nameid").val()},
success: function(msg){
//业务代码,改变页面的数据
//alert(msg);
if (msg==true){
$("#namewrongid").text("此用户名存在!");
$("#nameid").focus();
} else {
$("#namewrongid").text("此用户名不存在!");
$("#ageid").focus();
}
},
error:function(errordata){
alert("wrong!!"+errordata);
}
});
});
});
</script>
SSM框架完整开发流程的更多相关文章
- 一款APP的完整开发流程 (转载)
来源:https://www.sohu.com/a/239089829_100063940 近年来,在市场和政策的双轮驱动下,我国服务外包产业快速发展,服务智能化趋势显现.随着企业核心业务外包活动的日 ...
- MVC5+EF6 入门完整教程3 :EF完整开发流程
https://www.cnblogs.com/miro/p/4053473.html 学完本篇文章,你将会掌握基于EF数据模型的完整开发流程. 本次将会完成EF数据模型的搭建和使用. 基于这个模型, ...
- SSM框架——整合搭建流程
1.首先创建maven工程,使用哪种方式进行创建都可以,可以参考博主之前的文章: <两种方式创建Maven项目[方式二]><两种方式创建Maven项目[方式一]> 2.先看看搭 ...
- 使用.NET MVC框架项目开发流程(项目开发流程)
MVC项目开发流程 整理需求,进行需求分析.项目设计. 整理数据项,建数据库做前期准备,并整理字典. 建立所需数据库表和视图和模型. 页面实现其初步功能(跳过逻辑后台代码),只是实现页面之间的跳转以及 ...
- ssm框架的搭建流程
1.新建一个Maven project (1)选中create a simple project,自动配置必要的文件 (2)Packaging选择war类型.jar和war的区别就是一个是普通的jav ...
- SSM(Spring+SpringMVC+MyBatis)框架整合开发流程
回忆了 Spring.SpringMVC.MyBatis 框架整合,完善一个小demo,包括基本的增删改查功能. 开发环境 IDEA MySQL 5.7 Tomcat 9 Maven 3.2.5 需要 ...
- 完整开发流程管理提升与系统需求分析过程 随堂笔记(day 1) 【2019/10/14】
Top12原则: 主要资源,重要功能,依据需求重要度进行资源分配, 项目100功能 1 day -> 100Task -> 10 Dev 20% 80% 开发各阶段流程及规范 需求.架 ...
- ionic 实现微信朋友圈分享的完整开发流程
最近开始要着手负责开发ionic的项目了,一直很好奇想实现一个微信朋友圈分享的功能,所以我就网上找了找文章来练手实现,果不其然,找到了几篇,但是发现它们的流程都不太详细,清楚,直接,还有不少坑. 今天 ...
- 快速搭建SSM框架环境开发项目【配置】
maven在线仓库https://mvnrepository.com/ maven构建项目 pom.xml <project xmlns="http://maven.apache.or ...
随机推荐
- python3(六) for while
# Python的循环有两种,一种是for...in循环,依次把list或tuple中的每个元素迭代出来 names = ['Michael', 'Bob', 'Tracy'] for name in ...
- 解决从服务器获取的数组是 __NSCFConstantString以及""没有空格字符串的问题
AJ分享,必须精品 问题 项目遇到了个bug,从服务器获取到的数据是这样的 { status = 1, data = [ { uid = 161, type = 2, id = 79, addtime ...
- Shell 变量引用实例
初学 Shell 编程时,对变量各种引用使用不太熟悉,走了很多弯路,本文记录变量引用的一些用法,希望对大家有所帮助. 引用 引用指将字符串用引用符号引起来,以防止特殊字符被 shell 脚本解释为其他 ...
- Delphi学习手记——单引号和双引号的区别
单引号和双引号的区别 双引号表示其中字符可能包含变量,而单引号表示整个引号内的东西都当成字符串来处理. 也就是说:没有内设变量就用单引号'',有就用双引号"". 举例说明: $va ...
- C - Battle City BFS+优先队列
Many of us had played the game "Battle city" in our childhood, and some people (like me) e ...
- Python实现按键精灵(一)-键鼠操作
需要安装 pywin32库 pip install pywin32 import win32api import time #鼠标移动 def mouse_move(x,y): win32api.Se ...
- selenium获取多窗口句柄并一切换至原窗口句柄(三个窗口)
网上有很多是selenium基于python来获取两个窗口句柄与切换,本文实现用python+selenium获取多窗口句柄并一一切换至原窗口句柄(三个窗口),且在每个窗口下进行一个搜索或翻译,然后截 ...
- 不借助多余参数也可交换两个参数(c++,swap函数)
利用a^a=0异或属性 [示例代码] #include<stdio.h> void data_swap(int &a,int &b){ a = a ^ b; b = a ^ ...
- java IO流 之 字节流与字符流
其实学习了file文件基础类,后面的字节流和字符流都特别简单了,首先需要知道字节流和字符流的区别 字节流: 用来传送图片.各种文件.大文件.文本都是通过字节流进行传输的. 字符流: 只能读取文本信息 ...
- pytorch seq2seq模型中加入teacher_forcing机制
在循环内加的teacher forcing机制,这种为目标确定的时候,可以这样加. 目标不确定,需要在循环外加. decoder.py 中的修改 """ 实现解码器 &q ...