-
2020-01-14 18:54:47
前段时间学习了ssm的整合,通过做一个简易的学生信息小案例来加深印象。
源码已放到码云上:https://gitee.com/zhongxia621/student
ssm整合的思路是首先进行spring和mybatis的整合,然后进行spring和springmvc的整合
首先进行web.xml的配置,主要是对spring监听器和springmvc的springDispatcherServlet,以及内路径的配置(spring的applicationContext.xml和springmvc的applicationContext-controller.xml),controller/searchall的配置是为了当项目一启动就访问它。
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>SSM</display-name> <welcome-file-list> <welcome-file></welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file></welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <!-- Web项目中,引入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> <!-- 整合SPringMVC --> <servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-controller.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>/controller/searchall</url-pattern> </servlet-mapping> <!-- Map all requests to the DispatcherServlet for handling --> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>controller/searchall</welcome-file> </welcome-file-list> </web-app>
配置spring的applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 依赖注入:给service注入dao --> <bean id="studentService" class="org.lanqiao.service.impl.StudentServiceImpl"> <property name="studentMapper" ref="studentMapper"></property> </bean> <!-- 配置配置数据库信息(替代mybatis的配置文件conf.xml) --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/suzy?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=false"/> <property name="username" value="root"/> <property name="password" value="10086"/> </bean> <!-- conf.xml : 数据源,mapper.xml --> <!-- 配置MyBatis需要的核心类:SqlSessionFactory --> <!-- 在SpringIoc容器中 创建MyBatis的核心类 SqlSesionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <!-- 加载mapper.xml路径 --> <property name="mapperLocations" value="classpath:org/lanqiao/mapper/*.xml"></property> </bean> <!-- 将MyBatis的SqlSessionFactory 交给Spring --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> <property name="basePackage" value="org.lanqiao.mapper"></property> <!--上面basePackage所在的property的作用: 将org.lanqiao.mapper包中,所有的接口 产生与之对应的 动态代理对象 (对象名 就是 首字母小写的接口名) :studentMapper.querystudentBYNO(); --> </bean> </beans>
配置springmvc的applicationContext-controller.xml
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 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.3.xsd"> <!-- 将控制器所在包 加入IOC容器 --> <context:component-scan base-package="org.lanqiao.controller"></context:component-scan> <!-- 配置视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/views/"></property> <property name="suffix" value=".jsp"></property> </bean> <!-- SPringMVC基础配置、标配 --> <mvc:annotation-driven></mvc:annotation-driven> </beans>
接下来写mapper.xml也就是数据库增删改查所需要的语句
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namespace:该mapper.xml映射文件的 唯一标识 --> <mapper namespace="org.lanqiao.mapper.StudentMapper"> <select id="queryStudentByStuno" parameterType="int" resultType="org.lanqiao.entity.Student" > select * from student where stuno = #{stuNo} </select> <select id="searchall" resultType="org.lanqiao.entity.Student" > select * from student </select> <insert id="addStudent" parameterType="org.lanqiao.entity.Student" > insert into student(stuno,stuname,stuage) values(#{stuNo},#{stuName},#{stuAge}) </insert> <delete id="deleteStudent" parameterType="int"> delete from student where stuno = #{stuno} </delete> <update id="updateStudent" parameterType="org.lanqiao.entity.Student" > update student set stuname=#{stuName} ,stuage=#{stuAge} where stuno=#{stuNo} </update> </mapper>
学生实体类
package org.lanqiao.entity; public class Student { private int stuNo; private String stuName; private int stuAge ; public Student(int stuNo, String stuName, int stuAge) { this.stuNo = stuNo; this.stuName = stuName; this.stuAge = stuAge; } public Student() { } public int getStuNo() { return stuNo; } public void setStuNo(int stuNo) { this.stuNo = stuNo; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } public int getStuAge() { return stuAge; } public void setStuAge(int stuAge) { this.stuAge = stuAge; } }
接下来写studentmapper也就是所需要增删改查的接口(数据库层即dao层)
package org.lanqiao.mapper; import java.util.List; import org.lanqiao.entity.Student; public interface StudentMapper { public void addStudent(Student student ); Student queryStudentByStuno(int stuno); List<Student> searchall(); void deleteStudent(int stuno); void updateStudent(Student student); }
接下来写service层(接口和实现类)
package org.lanqiao.service; import java.util.List; import org.lanqiao.entity.Student; public interface StudentService { Student queryStudentByNo(int stuNo); void addStudent(Student student); List<Student> searchall(); void deleteStudent(int stuno); void updateStudent(Student student); }
package org.lanqiao.service.impl; import java.util.List; import org.lanqiao.entity.Student; import org.lanqiao.mapper.StudentMapper; import org.lanqiao.service.StudentService; public class StudentServiceImpl implements StudentService { //service依赖于dao(mapper) private StudentMapper studentMapper ; public void setStudentMapper(StudentMapper studentMapper) { this.studentMapper = studentMapper; } @Override public Student queryStudentByNo(int stuNo) { return studentMapper.queryStudentByStuno(stuNo) ; } @Override public void addStudent(Student student) { studentMapper.addStudent(student); } @Override public List<Student> searchall() { return studentMapper.searchall(); } @Override public void deleteStudent(int stuno) { studentMapper.deleteStudent(stuno); } @Override public void updateStudent(Student student) { studentMapper.updateStudent(student); } }
最后写controller层
package org.lanqiao.controller; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.lanqiao.entity.Student; import org.lanqiao.service.StudentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @RequestMapping("controller") @Controller//StudentController加入Ioc容器 public class StudentController { //控制器依赖于Service @Autowired @Qualifier("studentService") private StudentService studentService; public void setStudentService(StudentService studentService) { this.studentService = studentService; } @RequestMapping("queryStudentByNo/{stuno}") public String queryStudentByNo(@PathVariable("stuno") Integer stuNo ,Map<String,Object> map) { Student student = studentService.queryStudentByNo(stuNo) ; map.put("student", student) ; return "edit" ; } @RequestMapping("addStudent") public String addStudent( HttpServletRequest request,Map<String,Object> map) { int id = Integer.parseInt(request.getParameter("id")); String name = request.getParameter("name"); int age = Integer.parseInt(request.getParameter("age")); Student st=new Student(id, name, age); studentService.addStudent(st); List<Student> stu=studentService.searchall(); map.put("students", stu); return "show" ; } @RequestMapping("searchall") public String searchall(Map<String,Object> map) { List<Student> stu=studentService.searchall(); map.put("students", stu); return "show" ; } @RequestMapping("deleteStudent/{stuno}") public String deleteStudent(@PathVariable("stuno") Integer stuNo,Map<String,Object> map) { studentService.deleteStudent(stuNo); List<Student> stu=studentService.searchall(); map.put("students", stu); return "show" ; } @RequestMapping("updateStudent/{stuno}") public String updateStudent(@PathVariable("stuno") Integer stuNo,HttpServletRequest request,Map<String,Object> map) { String name = request.getParameter("name"); int age = Integer.parseInt(request.getParameter("age")); Student st=new Student(stuNo, name, age); studentService.updateStudent(st); List<Student> stu=studentService.searchall(); map.put("students", stu); return "show" ; } }
show.jsp(信息展示界面)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>学生信息</title> <style type="text/css"> *{ margin: 0px ; padding: 0px ; } a{ text-decoration: none ; } .nav-header { width: 100% ; height:85px ; background: gray; } .head-contain { width: 700px ; height: 85px ; margin:0 auto ; text-align:center ; } .top-nav,.top-nav li,.top-right { display: inline-block ; vertical-align:top ; margin-top: 15px ; } .top-nav li { width: 90px ; } .top-nav li a { font-size: 17px ; color: #fff ; } .top-nav li a:hover { color: blue ; } .top-right a { display:inline-block ; font-size: 17px ; margin-top: 10px ; border-radius:30px ; } .top-right a:first-of-type { width:75px ; height: 35px ; border:1px green solid ; line-height:35px ; } .top-right a:first-of-type:hover { color:red ; background: green; } </style> </head> <body> <header class="nav-header"> <div class="head-contain"> <nav class="top-nav"> <ul> <li><a href="http://localhost:8080/SSM/">学生信息</a></li> <li><a href="https://me.csdn.net/qq_39059193">博客</a></li> <li><a href="https://www.baidu.com/">百度</a></li> <li><a href="#">搜索</a></li> <li><a href="https://github.com/">github</a></li> </ul> </nav> <div class="top-right"> <a href="#">登录</a> <a href="#">注册</a> </div> </div> </header> <h1 align="center"> <a href="/SSM/add.jsp"><font size="5px">增加信息</font> </a></h1> <div align="center" class="table"> <table border="1px"> <tr> <th width="250px" height="50px">学号</th> <th width="250px" >姓名</th> <th width="250px" >年龄</th> <th width="100px" >编辑</th> <th width="100px" >删除</th> </tr> <c:forEach items="${requestScope.students }" var="student"> <tr> <td align="center" height="50px">${ student.stuNo}</td> <td align="center">${ student.stuName}</td> <td align="center">${ student.stuAge}</td> <td align="center"><a href="/SSM/controller/queryStudentByNo/${student.stuNo}">编辑</a></td> <td align="center"><a href="/SSM/controller/deleteStudent/${student.stuNo}">删除</a></td> </tr> </c:forEach> </table> </div> </body> </html>
增加信息界面add.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <form action="controller/addStudent" method="post"> 学号:<input type="text" name="id"><br> 姓名:<input type="text" name="name"><br> 年龄:<input type="text" name="age"><br> <input type="submit" value="增加"><br> </form> </body> </html>
编辑信息界面edit.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>修改信息</title> </head> <body> <form action="../updateStudent/${student.stuNo}" method="post"> 姓名:<input type="text" name="name"><br> 年龄:<input type="text" name="age"><br> <input type="submit" value="修改"><br> </form> </body> </html>
所需要的jar包
效果展示:
增加学号为10姓名为lyf年龄为32的信息
增加后信息
删除学号为8的信息
修改学号为3的信息
修改后信息
只是一个简易学生信息,没有分页搜索等。
更多相关内容 -
学生信息增删改查
2013-12-18 15:49:14用VC实现学生信息管理系统 ,实现数据的结构化存储及可视化界面的完成。 -
java大作业,实现学生信息增删改查
2013-08-01 19:09:22编写Web应用程序(JavaEE平台上的应用,能够运行在Tomcat服务器上),实现学生信息的增删改查。 在Web页面上实现添加一个学生记录,删除某个学生记录,修改某个学生记录,和按照姓名,学号进行查询。 要求列表输出... -
学生信息增删改查和分页查询
2018-02-19 20:08:15java Servlet+mysql开发学生信息增删改查和分页查询功能,适合java web开发初学者 控制层:servlet 数据库:mysql IDE工具:eclipse 功能:增删改查+分页 内含所有所需jar包,下载后改数据库连接密码即可运行 -
路由+增删改查(vue)
2019-12-04 17:35:46不描述了 搞着好玩的!!!!也不知道说什么。。 。 -
基于javaee实现对学生信息的增删改查的2种方法
2017-12-17 17:17:17基于javaee实现对学生信息的增删改查以及显示,通过控制器以及struts 2种方法实现。 -
学生信息管理系统(源码+数据库+构架文档) jsp web+MySQL 满足增删改查
2017-06-21 11:03:13适合学生交项目,满足增删改查 -
Servlet +jsp+jdbc增删改查学生信息
2019-01-07 23:01:14简单的jsp+servlet+jdbc+javaBean实现的增删查改项目,供新手参考 -
C#实现学生信息管理系统(包括增删改查功能)——亲测可用
2021-12-12 12:54:47C#实现学生信息管理系统(包括增删改查功能)——亲测可用 -
安卓实现学生的增删改查以及其他功能.zip
2020-03-01 21:42:11安卓实现的学生的增删改查的操作 -
学生管理系统—JavaWeb项目-SSM框架整合-增删改查
2018-12-22 12:05:45spring+springMVC+Mybatis实现学生管理系统增删改查,数据库中有两张表:student学生和class班级表。使用Myabtis逆向生成以及分页插件,以及批量操作,前端使用bootstrap框架搭建。 -
简单的学生信息增删改查
2012-11-22 11:22:55信息的查询 添加 删除 修改 三层架构 可以运行的哦 -
C语言学生管理系统_数据的增删改查_学习
2022-06-04 20:42:58该做平包含1、录入学生信息 2、打印学生信息 3、保存学生信息 4、读取学生信息 5、统计所有学生人数 6、查找学生信息 7、修改学生信息 8、删除学生信息 0、退出系统 9个功能 -
VS2019 C# MySQL 学生信息增删改查(一、增删)
2020-10-24 10:17:50VS2019 C# MySQL 学生信息增删改查 由于刚刚学习VS2019,入手的第一个例子是编写一个简单的增删改查。这里,我以学生信息为例,进行详细的过程描述以及代码实现。 一、 新建一个Windows窗体应用程序 1、创建新项目...VS2019 C# MySQL 学生信息增删改查
由于刚刚学习VS2019,入手的第一个例子是编写一个简单的增删改查。这里,我以学生信息为例,进行详细的过程描述以及代码实现。
一、 新建一个Windows窗体应用程序
1、创建新项目界面,如下图所示。
2、更改项目名称,当然不修改也可以。我这里的是“StudentInfoSystem”;项目存放位置路径根据自己需要进行更改;“将解决方案和项目放在同一目录中”前面的勾选框,选不选都可以;点击“创建”,如下图所示。
二、前期准备工作1、将Form1属性中的Text的“Form1”改为“学生管理系统首页”,并从工具箱中拖入4个Button按钮放在设计界面上,如下图所示。分别将“button1”、“button2”、“button3”、“button4”属性中的(Name)改为“BtnZeng”、“BtnShan”、“BtnGai”、“BtnCha”,并分别将其属性中的Text改为“增加”、“删除”、“修改”、“查看”。
2、(1)鼠标选中“StudentInfoSystem”,右击选中“添加”,找到“窗体(Windows窗体)”,如下图所示。
(2)增加4个Form设计界面,分别将其属性中的(Name)改为FormZengJia、FormShanChu、FormXiuGai、FormChaKan,并分别修改其属性Text为“增加”、“删除”、“修改”、“查看”,如下图所示。
3、分别双击增加、删除、修改、查看四个按钮,将4个设计界面连接到主界面上,添加代码,如下。public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void BtnZeng_Click(object sender, EventArgs e) { FormZengJia zengJia = new FormZengJia(); zengJia.Show(); } private void BtnShan_Click(object sender, EventArgs e) { FormShanChu shanChu = new FormShanChu(); shanChu.Show(); } private void BtnGai_Click(object sender, EventArgs e) { FormXiuGai xiuGai = new FormXiuGai(); xiuGai.Show(); } private void BtnCha_Click(object sender, EventArgs e) { FormChaKan chaKan = new FormChaKan(); chaKan.Show(); } }
三、建立数据库
我用的是MySQL。
1、新建数据库,如下图所示。
2、数据库表设计,如下图所示。
四、增1、在FormZengJia界面中拖入控件,如下图所示。
2、修改TextBox以及Button中的相应属性,如下图所示。
3、双击“增加一条记录”按钮,进入代码界面,首先的工作就是引入,右击“引用”,选择“添加引用 | 浏览”,找到自己安装MySQL文件中的“MySql.Data.dll”,如下图所示。
4、在头文件中将“using MySql.Data.MySqlClient;”引入进来,如下。using MySql.Data.MySqlClient;
5、代码如下:
private void BtnZeng_Click(object sender, EventArgs e) { String connectStr = "server=localhost;database=studentinfosystem;user=root;password=123456;port=3306;charset=utf8"; //server=127.0.0.1或localhost。database是我的数据库名,studentinfosystem是新建的数据库名。 //我这里的user是root,密码是123456(安装MySQl时自己设置的密码)。端口号port一般都是3306。 //charset字符集一定要加,不加的话,虽然连接成功,但如果含有中文,就显示不了中文内容。 MySqlConnection conn = new MySqlConnection(connectStr); conn.Open();//打开通道,建立连接 //下面主要就是条件判断 if (tbno.Text == "") { MessageBox.Show("学号不能为空"); } else if (tbname.Text == "") { MessageBox.Show("姓名不能为空"); } else if (tbno.Text != "" && tbname.Text != "") { string str = ""; if (tbdept.Text.Trim().Length == 0 && tbbirth.Text.Trim().Length == 0) { str = "insert into info(学号,姓名) values('" + tbno.Text + "','" + tbname.Text + "')";//info是数据库表名 } else if (tbdept.Text.Trim().Length == 0 && tbbirth.Text.Trim().Length > 0) { str = "insert into info(学号,姓名,出生日期) values('" + tbno.Text + "','" + tbname.Text + "','" + tbbirth.Text + "')"; } else if (tbdept.Text.Trim().Length > 0 && tbbirth.Text.Trim().Length == 0) { str = "insert into info(学号,姓名,专业) values('" + tbno.Text + "','" + tbname.Text + "','" + tbdept.Text + "')"; } else if (tbdept.Text.Trim().Length > 0 && tbbirth.Text.Trim().Length > 0) { str = "insert into info(学号,姓名,专业,出生日期) values('" + tbno.Text + "','" + tbname.Text + "','" + tbdept.Text + "','" + tbbirth.Text + "')"; } try { MySqlCommand cmd = new MySqlCommand(str, conn); cmd.ExecuteNonQuery(); } catch (MySqlException ex) { MessageBox.Show(ex.Message); } int s = 1; if (s == 1) { MessageBox.Show("成功增加一条记录"); tbno.Clear(); tbname.Clear(); tbdept.Clear(); tbbirth.Clear();//清空TextBox中的数据 } } conn.Close(); }
6、点击“启动”,添加一条记录看看效果,显示“成功增加一条记录”,回到数据库表中,刷新一下,发现刚刚添加的记录已经成功保存到数据库表中了,如下图所示。
五、删1、在FormShanChu界面中拖入控件,更改相应的属性,如下图所示。
2、双击“删除一条记录”按钮,进入代码界面,在头文件中将“using MySql.Data.MySqlClient;”引入进来。3、代码如下:
private void BtnDelete_Click(object sender, EventArgs e) { String connectStr = "server=localhost;database=studentinfosystem;user=root;password=123456;port=3306;charset=utf8"; //server=127.0.0.1或localhost。database是我的数据库名,studentinfosystem是新建的数据库名。 //我这里的user是root,密码是123456(安装MySQl时自己设置的密码)。端口号port一般都是3306。 //charset字符集一定要加,不加的话,虽然连接成功,但如果含有中文,就显示不了中文内容。 MySqlConnection conn = new MySqlConnection(connectStr); conn.Open();//打开通道,建立连接 //下面主要是条件判断 string str = ""; if (tbno.Text.Trim().Length == 0 && tbname.Text.Trim().Length == 0) { MessageBox.Show("请输入要删除的学号或姓名!"); } else if (tbno.Text.Trim().Length > 0 && tbname.Text.Trim().Length == 0) { str = "delete from info where 学号='" + tbno.Text + "'";//按“学号”删除 } else if (tbno.Text.Trim().Length == 0 && tbname.Text.Trim().Length > 0) { str = "delete from info where 姓名='" + tbname.Text + "'";//按“姓名”删除 } else if (tbno.Text.Trim().Length > 0 && tbname.Text.Trim().Length > 0) { str = "delete from info where 学号='" + tbno.Text + "'and 姓名='" + tbname.Text + "'";//按“学号+姓名”删除 } try { MySqlCommand cmd = new MySqlCommand(str, conn); cmd.ExecuteNonQuery(); } catch (MySqlException ex) { MessageBox.Show(ex.Message); } int s = 1; if (s == 1) { MessageBox.Show("删除成功"); tbno.Clear(); tbname.Clear();//清空 } conn.Close(); }
4、点击“启动”,删除一条记录看看效果,显示“删除成功”,回到数据库表中,刷新一下,发现刚刚删除的记录已经成功删除,如下图所示。
-
学生信息管理系统(tkinter界面带登陆系统,增删改查等)-python
2022-05-30 23:36:56登陆账号密码核对、验证码、注册登录信息、添加学生... 通过连接个人MySQL数据库进行存储登陆账号密码,并实现从所存储的表中读取学生姓名学号班级等信息,进行增删改查。如有疑问联系邮箱:2386475288@qq.com,谢谢。 -
【初学者适用】Java学生信息管理简单增删改查
2019-03-07 11:32:14【初学者适用】Java学生信息管理简单增删改查,能够给大家带来一定好处。 -
C语言实现学生信息管理的增删改查
2019-04-11 01:41:55NULL 博文链接:https://yrcn.iteye.com/blog/1687785 -
利用ssm整合实现对用户的增删改查
2020-06-13 00:06:53利用ssm(spring+springmvc+mybatis)整合实现对用户的增删改查,写的比较简单易懂,非常适合初学者学习。 -
python 终端学生管理系统,学生增删改查
2022-04-12 14:50:52请输入用户名:admin ...登录成功,欢迎你,admin ==== MAIN MENU ==== 1. 查看学生列表 2. 添加学生 3. 修改学生信息 4. 删除学生 5. 显示操作菜单 ==== MAIN MENU ==== 请输入一个代码执行操作exit()退出: -
jsp+mysql增删改查,有用户登陆,注册,学生信息显示,修改,查询,删除功能
2019-01-24 16:24:50本系统为简单的jsp+mysql增删改查例子,有用户登陆,注册,学生信息显示,修改,查询,删除功能,也可以管理登陆用户信息,对于刚开始学习jsp的同学有很好的参考性。 PS:在数据库中先建立mldn数据库,然后将mldn.... -
VS2019 C# MySQL 学生信息增删改查(二、改查(续前节))
2020-10-24 11:36:40VS2019 C# MySQL 学生信息增删改查 六、改 1、在FormXiuGai界面中拖入控件,更改相应的属性,如下图所示。 思路:先查找,再将查找到的数据显示在TextBox上,再进行修改。我这里设置学号不可修改,点击学号后的...VS2019 C# MySQL 学生信息增删改查
六、改
1、在FormXiuGai界面中拖入控件,更改相应的属性,如下图所示。
思路:先查找,再将查找到的数据显示在TextBox上,再进行修改。我这里设置学号不可修改,点击学号后的TextBox文本框,在属性栏找到Enabled,设置为False(不可修改),这样用户就只能修改除学号以外的内容。
2、双击“查询”按钮,编码,如果找到,就显示在右侧的文本框中;如果找不到,弹出提示框,代码如下。
(记得在头文件引入:using MySql.Data.MySqlClient;)private void BtnChaXun_Click(object sender, EventArgs e) { String connectStr = "server=localhost;database=studentinfosystem;user=root;password=123456;port=3306;charset=utf8"; //server=127.0.0.1或localhost。database是我的数据库名,studentinfosystem是新建的数据库名。 //我这里的user是root,密码是123456(安装MySQl时自己设置的密码)。端口号port一般都是3306。 //charset字符集一定要加,不加的话,虽然连接成功,但如果含有中文,就显示不了中文内容。 MySqlConnection conn = new MySqlConnection(connectStr); conn.Open();//打开通道,建立连接 string str = "select *from info where 学号=" + tbxuehao.Text; MySqlCommand command = new MySqlCommand(str, conn); MySqlDataReader mySqlDataReader = command.ExecuteReader(); if (mySqlDataReader != null) { MessageBox.Show("查询成功"); mySqlDataReader.Read(); tbno.Text = mySqlDataReader[1].ToString(); //将查询结果显示在文本框 tbname.Text = mySqlDataReader[2].ToString(); tbdept.Text = mySqlDataReader[3].ToString(); tbbirth.Text = mySqlDataReader[4].ToString(); } else { MessageBox.Show("请重新输入"); } }
3、双击“修改”按钮,编码,代码如下。
private void BtnUpdate_Click(object sender, EventArgs e) { String connectStr = "server=localhost;database=studentinfosystem;user=root;password=123456;port=3306;charset=utf8"; //server=127.0.0.1或localhost。database是我的数据库名,studentinfosystem是新建的数据库名。 //我这里的user是root,密码是123456(安装MySQl时自己设置的密码)。端口号port一般都是3306。 //charset字符集一定要加,不加的话,虽然连接成功,但如果含有中文,就显示不了中文内容。 MySqlConnection conn = new MySqlConnection(connectStr); conn.Open();//打开通道,建立连接 string str = "update info set 姓名='" + tbname.Text + "',专业='" + tbdept.Text + "',出生日期='" + tbbirth.Text + "'where 学号='" + tbxuehao.Text + "'"; MySqlCommand command = new MySqlCommand(str, conn); command.ExecuteNonQuery(); MessageBox.Show("修改成功"); }
4、点击“启动”,查询一条记录看看效果,显示“查询成功”;再修改信息,点击“修改”按钮,提示“修改成功”。回到数据库表中,刷新一下,发现刚刚修改的记录已经成功修改,如下图所示。
七、查1、在FormChaKan界面中拖入控件,更改相应的属性,如下图所示。
2、双击“确定”按钮,进行编码,代码如下。
(记得在头文件引入:using MySql.Data.MySqlClient;)private void BtnOK_Click(object sender, EventArgs e) { String connectStr = "server=localhost;database=studentinfosystem;user=root;password=123456;port=3306;charset=utf8"; //server=127.0.0.1或localhost。database是我的数据库名,studentinfosystem是新建的数据库名。 //我这里的user是root,密码是123456(安装MySQl时自己设置的密码)。端口号port一般都是3306。 //charset字符集一定要加,不加的话,虽然连接成功,但如果含有中文,就显示不了中文内容。 MySqlConnection conn = new MySqlConnection(connectStr); conn.Open();//打开通道,建立连接 string str = "select *from info "; if (tbno.Text.Trim().Length > 0) { str += "where 学号='" + Convert.ToInt32(tbno.Text) + "'"; } if (tbname.Text.Trim().Length > 0) { if (str.Contains("where")) { str += "and 姓名='" + tbname.Text + "'"; } else { str += "where 姓名='" + tbname.Text + "'"; } } if (tbdept.Text.Trim().Length > 0) { if (str.Contains("where")) { str += "and 专业='" + Convert.ToInt32(tbdept.Text) + "'"; } else { str += "where 专业='" + Convert.ToInt32(tbdept.Text) + "'"; } } if (tbbirth.Text.Trim().Length > 0) { if (str.Contains("where")) { str += "and 出生日期='" + Convert.ToInt32(tbbirth.Text) + "'"; } else { str += "where 出生日期='" + Convert.ToInt32(tbbirth.Text) + "'"; } } MySqlCommand comm = new MySqlCommand(str, conn); comm.ExecuteNonQuery(); MySqlDataAdapter mysd = new MySqlDataAdapter(comm); DataSet ds = new DataSet(); mysd.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; conn.Close(); }
3、点击“启动”,查看一条记录,如下图所示。
到这儿,简单学生管理系统的增删改查操作就全部完成。文中如有发现错误,欢迎指正!
-
基于Python3 tkinterGUI界面实现读取本地Excel文件进行增删改查的学生信息管理系统源代码.rar
2020-07-23 11:06:46基于Python3 tkinterGUI界面实现读取存储本地Excel文件进行增删改查的学生信息管理系统的可执行exe文件,openpyxl实现对Excel文件的增删改查及存储至本地文件。界面展示效果下载后用Python开发工具运行即可展示,可... -
jsp+servlet+javabean实现数据库增删改查操作
2017-03-27 11:55:28实现日志的增删改查,适合java初学者 -
学生管理系统(增删改查)
2019-04-09 10:48:29用java做的界面,MySQL作为后台数据库,可以实现对学生表的增删改查 -
使用java对学生表进行增删改查
2020-07-08 13:56:11使用java建立简单窗口,连接SQL Server数据库,并且在此窗口中对学生表进行增删改查等功能; -
SSM框架实现信息管理(增删改查)简单项目ssm.zip
2021-07-29 11:04:04SSM框架实现信息管理(增删改查)简单项目 -
springboot+mybatis+mysql+layUI+thymeleaf实现对学员信息的增删改查
2020-04-07 10:01:13springboot+mybatis+mysql+layUI+thymeleaf实现对学员信息的增删改查 -
利用对象数组对员工,学生增删改查
2016-09-11 12:21:55利用对象数组对人员增删改查,简单实现! -
servlet+jsp+jdbc的学生信息的增删改查
2013-04-18 15:36:04用jdbc连接数据库,用servlet控制web界面。实现对数据的增删改查。