SSM框架实现数据库增删查改
搭建好框架后,⽅法的实现步骤就⼤同⼩异了,要写的代码不多。但是因为这个是结合前端实现的,所以整个⼯程还是挺⼤的,不是这⼏⾏代码可以写清楚的。
⾸先,看看界⾯
⽤户管理主界⾯:
⽤户添加界⾯:
然后,看下⼯程⽬录:
以添加为例:1.User类
package com.wuli.bean;
public class User {
private int id;
private String username;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
//构造⽅法
public User(int id, String username, String password) { this.id = id;
this.username = username;
this.password = password;
}
public User() {
}
//toString
@Override
public String toString() {
return "User{" +
"id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
2.UserDao类
void addUser(User user);
3.UserService接⼝
void addUser(User user);
4.UserServiceImpl类
@Override
public void addUser(User user) {
userDao.addUser(user);
}
5.UseerController类
@RequestMapping("/addUser")
public String addUser(User user){
//调⽤service⽅法
userService.addUser(user);
/
/重定向
return "redirect:findAllUser.do";
}
6.在l中写SQL语句
<!--增加-->
<insert id="addUser" parameterType="com.wuli.bean.User">
insert into tb_user(id,username,password) values (#{id},#{username},#{password})
</insert>
7.user-add.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"> <html>
<head>
<!-- 页⾯meta -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>数据 - AdminLTE2定制版</title>
<meta name="description" content="AdminLTE2定制版">
<meta name="keywords" content="AdminLTE2定制版">
<!-- Tell the browser to be responsive to screen width -->
<meta
content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"
name="viewport">
<link rel="stylesheet"
href="${tPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet"
href="${tPath}/plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet"
href="${tPath}/plugins/ionicons/css/ionicons.min.css">
<link rel="stylesheet"
href="${tPath}/plugins/iCheck/square/blue.css">
<link rel="stylesheet"
href="${tPath}/plugins/morris/morris.css">
<link rel="stylesheet"
href="${tPath}/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
<link rel="stylesheet"
href="${tPath}/plugins/datepicker/datepicker3.css">
<link rel="stylesheet"
href="${tPath}/plugins/daterangepicker/daterangepicker.css">
<link rel="stylesheet"
href="${tPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
href="${tPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
<link rel="stylesheet"
href="${tPath}/plugins/datatables/dataTables.bootstrap.css">
<link rel="stylesheet"
href="${tPath}/plugins/able.css">
<link rel="stylesheet"
href="${tPath}/plugins/able.theme.default.css">
<link rel="stylesheet"
href="${tPath}/plugins/select2/select2.css">
<link rel="stylesheet"
href="${tPath}/plugins/colorpicker/bootstrap-colorpicker.min.css">
<link rel="stylesheet"
href="${tPath}/plugins/bootstrap-markdown/css/bootstrap-markdown.min.css"> <link rel="stylesheet"
href="${tPath}/plugins/adminLTE/css/AdminLTE.css">
<link rel="stylesheet"
href="${tPath}/plugins/adminLTE/css/skins/_all-skins.min.css">
<link rel="stylesheet"
href="${tPath}/css/style.css">
<link rel="stylesheet"
href="${tPath}/plugins/ionslider/ion.rangeSlider.css">
<link rel="stylesheet"
href="${tPath}/plugins/ionslider/ion.rangeSlider.skinNice.css">
<link rel="stylesheet"
href="${tPath}/plugins/bootstrap-slider/slider.css">
<link rel="stylesheet"
href="${tPath}/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css"> </head>
<body class="hold-transition skin-purple sidebar-mini">
<div class="wrapper">
<!-- 页⾯头部 -->
<jsp:include page="header.jsp"></jsp:include>
<!-- 页⾯头部 /-->
<!-- 导航侧栏 -->
<jsp:include page="aside.jsp"></jsp:include>
<!-- 导航侧栏 /-->
<!-- 内容区域 -->
<div class="content-wrapper">
<!-- 内容头部 -->
<section class="content-header">
<h1>
⽤户管理 <small>⽤户表单</small>
</h1>
<ol class="breadcrumb">
<li><a href="#"><i
class="fa fa-dashboard"></i> ⾸页</a></li>
<li><a
href="#">⽤户管理</a></li>
<li class="active">⽤户表单</li>
</ol>
</section>
<!-- 内容头部 /-->
<form action="${tPath}/user/addUser.do"
method="post">
jquery框架搭建<!-- 正⽂区域 -->
<section class="content"> <!--产品信息-->
<div class="panel panel-default">
<div class="panel-heading">⽤户信息</div>
<div class="row data-type">
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论