ssm框架集合mysql考试_SSM框架完整开发流程

这篇博客详细介绍了从数据库建模到使用SSM(Spring、SpringMVC、Mybatis)框架进行Web开发的全过程,包括MySQL的远程访问配置、Mybatis的代码生成、SSM的集成、拦截器的使用以及多表查询。还涵盖了文件上传下载、Excel数据导出、Ajax异步请求等进阶操作。
摘要由CSDN通过智能技术生成

----------------第一阶段--------------

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

2)targetPackage="com.softjx.model"

3)把表名与类名对应

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.

c.在WEB-INF同一层目录中建一个upload目录

d.上传文件的jsp界面

文件:

描述:

e.编写上传文件的action

2)文件下载

a.在WEB-INF同一层目录中建一个upload目录

b.下载的url:

通过 文件流 的方式下载文件hibernate1.jpg

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语句

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

select

distinct

FROM student a

left join school b on a.t_sid=b.t_id

order by ${orderByClause}

4).在dao中编写一个接口

//多表查询

List selectByExampleWithSchool(StudentExample example);

5).在service层编写接口与接口的实现

//多表查询

public List getStudentWithSchool(StudentExample studentExample);

public List 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语句

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

select

FROM student a

left join school b on a.t_sid=b.t_id

where a.t_id = #{tId,jdbcType=INTEGER}

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的配置文件,添加拦截器

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)编写一个

2)编写接口中方法的实现

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

4.在service中编写接口方法与实现。

--------------------第十阶段 使用jquery中的ajax技术--------------------

1.需要一个jquery的类库.js  放到static目录下,要注意拦截器放行。

2.jsp中导入js类库。

jquery的环境搭建完毕。

3.在springmvc中开发一个业务方法。

@ResponseBody//返回的数据是json数据

@RequestMapping("/studentName")

public List getStudentName(Map map, Student student) {

StudentExample studentExample = new StudentExample();

Criteria criteria = studentExample.createCriteria();

if (student.gettName() != null && !student.gettName().trim().equals(""))

criteria.andTNameEqualTo(student.gettName());

List students = studentService.getStudents(studentExample);

return students;

}

注意:1)返回值是对象类型或者是基本类型,2)@ResponseBody//返回的数据是json数据

4.在jsp页面上控制我们操作的构件,使用jquery的选择器,选中此对象。

5.编写ajax代码

$(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);

}

});

});

});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用到的技术:redis、amcharts、maven、html5、ajax、js、jquery以及css,关系型数据库采用的是mysql。 文件夹中有可以直接导入使用的数据库,以及可以导入试卷的excel表格格式. 该项目分为学生模块,和教师模块。 教师模块:教师可以通过导入Excel表格的方式进行添加试卷,如果Excel表中有不合法的数据,会在前台提醒哪一行哪一列出了什么问题,添加试卷后,教师可以发布试卷,试卷发布后,学生就可以答题,每张试卷都有作答时长,作答时间结束,将会自动提交试卷。考试结束后,教师可以发布答案。对于修改试卷,教师可以先选择所要修改的试卷,对于试卷可以修改试卷的名称以及考试时长,要想修改试题可以点击编辑试题,进行批量修改。 学生模块:注册登录进入学生考试平台,选择考卷,进行作答,试卷分为单选题、多选题以及判断题,分值各不相同,对于多选题错答不得分,漏答得一半的分。在作答期间,学生可以先保存,保存的内容存储在Redis中。若点击提交,提交后直接显示成绩。提交后就不能再进入考试。要想看正确答案,得等到考试结束,教师发布成绩后,才可以看到。 学生可以看到自己的作答历史,每道题之前学生的答案以及该题正确的答案都很清晰的标注出来。为了方便学生统计自己的成绩,本系统采用了amcharts技术根据学生的历次成绩制作了柱状图和折线图结合的图表。学生可以很直观地看到自己成绩的波动。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值