前言

   前段时间在博客园上找了一个springmvc的例子,照着学了一下,算是对springmvc有了一个初步的了解,打一个基础,下面是链接。(我只看了博客,视频太耗时间了)

   博客链接:http://www.cnblogs.com/bigdataZJ/p/springmvc1.html

   视频链接:http://ke.atguigu.com/course/48

   老师前几天让我练习一下用ajax做增删改查,只给了我一张数据库的表,什么都不多说。过程肯定是十分痛苦,因为技术方面只是略知一二,真正做的时候真的是无从下手,老师又什么都不告诉你,顾着自己的事,网上各种百度,找学长帮忙,但是毕竟学长也很忙,所以说学习真的还是要看自己。不过,花了整整四天的时间,终于还是做出来了,功夫不负有心人。虽然做的真的是相当的low,代码方面也还有很多不足的地方。

   最终效果展示页面:

   

  准备工作

   打开myecipse2014,打开数据库服务,打开navicat,将表导入数据库......等等,我就不多说了。

  配置

   新建maven项目工程

   WEB-INF目录下的web.xml  

   

 <?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"> <!-- 配置DispatchcerServlet -->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置Spring mvc下的配置文件的位置和名称 -->
<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>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping> <servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping> <servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping> <servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping> <servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping> <filter>
<filter-name>SpringEncodingFilter</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>SpringEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>

web.xml

   src目录下的springmvc.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: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"> <mvc:default-servlet-handler/>
<mvc:annotation-driven></mvc:annotation-driven> <!-- 配置自动扫描的包 -->
<context:component-scan base-package="com.jackie.springmvc.*"></context:component-scan> <!-- 配置视图解析器 如何把handler 方法返回值解析为实际的物理视图 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value="/WEB-INF/"></property>
<property name = "suffix" value = ".jsp"></property>
</bean> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="i18n"></property>
</bean> <!-- 配置SessionLocaleResolver -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"></bean> <!-- 配置LocaleChangeInterceptor -->
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"></bean>
</mvc:interceptors> <!-- <mvc:view-controller path="/i18n" view-name="i18n"/> -->
<mvc:view-controller path="/i18n2" view-name="i18n2"/> </beans>

springmvc.xml

   WEB-INF目录下的lib jar包

   没弄明白博客园能不能传文件,我把我的jar包截图发上来,不保证所有jar包都是需要的。(我直接复制的老师某个项目的lib文件夹)

   

   

       

        

  java代码

   

   

 package com.jackie.springmvc.ajax.controller;

 import java.util.HashMap;
import java.util.Map; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.fastjson.JSONArray;
import com.jackie.springmvc.ajax.dao.OlderDao; @Controller
public class OlderController { @Autowired
private OlderDao olderDao; //@CrossOrigin(origins="http://192.168.43.158:8080/TestSpringMVC/older", maxAge=3600)
@ResponseBody
@RequestMapping("/olders")
public Map<String, Object> olders(){
JSONArray dataJson = olderDao.getData("select * from peoplespecialcare");
Map<String, Object> map =new HashMap<String, Object>();
map.put("rows",dataJson);
map.put("total", olderDao.count); return map;
} @RequestMapping(value="/older/delete")
public String delete(Integer id) {
olderDao.getData("delete from peoplespecialcare where id = " + id); return "redirect:/ajaxOperation.jsp";
} @ResponseBody
@RequestMapping("/older/search")
public Map<String, Object> search(String peoplename){
JSONArray dataJson = olderDao.getData("select * from peoplespecialcare where peoplename=" + "'" + peoplename + "'");
Map<String, Object> map =new HashMap<String, Object>();
map.put("rows",dataJson);
map.put("total", olderDao.count); return map;
} @RequestMapping(value="/older/add")
public String add(Integer id, Integer peopleid, String peoplename, Integer servicestatusid,
Integer feespecialid, Double chargefee, Integer periodicalid,
Double startdate, Double enddate, Integer isfeeflagid, String remark) {
String sqlStr = "insert into peoplespecialcare(id, peopleid, peoplename, servicestatusid, feespecialid, chargefee, periodicalid, startdate, enddate, isfeeflagid, remark)values("+id+", "+peopleid+", '"+peoplename+"', "+servicestatusid+", "+feespecialid+", "+chargefee+", "+periodicalid+", "+startdate+", "+enddate+", "+isfeeflagid+", '"+remark+"')";
olderDao.getData(sqlStr); return "redirect:/ajaxOperation.jsp";
} @RequestMapping(value="/older/update")
public String update(Integer id, Integer peopleid, String peoplename, Integer servicestatusid,
Integer feespecialid, Double chargefee, Integer periodicalid,
Double startdate, Double enddate, Integer isfeeflagid, String remark) {
String sqlStr = "update peoplespecialcare set peopleid="+peopleid+", peoplename='"+peoplename+"', servicestatusid="+servicestatusid+", feespecialid="+feespecialid+", chargefee="+chargefee+", periodicalid="+periodicalid+", startdate="+startdate+", enddate="+enddate+", isfeeflagid="+isfeeflagid+", remark='"+remark+"' WHERE id="+id+"";
olderDao.getData(sqlStr); return "redirect:/ajaxOperation.jsp";
} }

OlderController

   

package com.jackie.springmvc.ajax.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; import org.springframework.stereotype.Repository; import com.alibaba.fastjson.JSONArray;
import com.jackie.springmvc.ajax.entities.Older; @Repository
public class OlderDao {
public int count = 0;
public JSONArray getData(String sql) {
String driver = "com.mysql.jdbc.Driver";
String username = "root";
String password = "zhao1110";
String url = "jdbc:mysql://localhost:3306/fhsystem?user="
+ username + "&password=" + password + "&useUnicode=true&characterEncoding=UTF-8";
JSONArray array = new JSONArray();
String sql1 = sql.substring(0, 6);
try {
Class.forName(driver);
Connection con = DriverManager.getConnection(url);
Statement stet = con.createStatement();
if(sql1.equals("select")) {
ResultSet rs = stet.executeQuery(sql); while(rs.next()){
int id = rs.getInt("id");
int peopleid = rs.getInt("peopleid");
String peoplename = rs.getString("peoplename");
int servicestatusid = rs.getInt("servicestatusid");
int feespecialid = rs.getInt("feespecialid");
double chargefee = rs.getDouble("chargefee");
int periodicalid = rs.getInt("periodicalid");
double startdate = rs.getDouble("startdate");
double enddate = rs.getDouble("enddate");
int isfeeflagid = rs.getInt("isfeeflagid");
String remark = rs.getString("remark");
double optime = rs.getDouble("optime");
int opuserid = rs.getInt("opuserid");
String opip = rs.getString("opip");
String r1 = rs.getString("r1");
String r2 = rs.getString("r2");
String r3 = rs.getString("r3");
String r4 = rs.getString("r4");
String r5 = rs.getString("r5");
count = rs.getRow();
Older older = new Older(id, peopleid, peoplename, servicestatusid,
feespecialid, chargefee, periodicalid, startdate, enddate,
isfeeflagid, remark, optime, opuserid, opip, r1, r2, r3, r4, r5);
array.add(older);
/*System.out.println(" " + id + " " + peopleid + " " + peoplename
+ " " + servicestatusid + " " + feespecialid + " " + chargefee
+ " " + periodicalid + " " + startdate + " " + enddate
+ " " + isfeeflagid + " " + remark + " " + optime
+ " " + opuserid + " " + opip + " " + r1 + " " + r2
+ " " + r3 + " " + r4); */
} //System.out.println("转换JSON数据:");
//System.out.println(array.toString());
rs.close();
stet.close();
con.close();
} else {
stet.executeUpdate(sql);
stet.close();
con.close();
/*sql="insert into peoplespecialcare(id, peopleid, peoplename, servicestatusid,
feespecialid, chargefee, periodicalid, startdate, enddate,
isfeeflagid)values('"+id+"', '"+peopleid+"', '"+peoplename+"', '"+servicestatusid+"', '"+feespecialid+"'
, '"+chargefee+"', '"+periodicalid+"', '"+startdate+"', '"+enddate+"', '"+isfeeflagid"')";
*/
}
} catch(java.lang.ClassNotFoundException e) {
//加载JDBC错误,所要用的驱动没有找到
System.err.print("ClassNotFoundException");
//其他错误
System.err.println(e.getMessage());
} catch (SQLException ex) {
//显示数据库连接错误或查询错误
System.err.println("SQLException: " + ex.getMessage());
} return array;
}
}

OlderDao.java  

   

package com.jackie.springmvc.ajax.entities;

public class Older {
private Integer id;
private Integer peopleid;
private String peoplename;
private Integer servicestatusid;
private Integer feespecialid;
private double chargefee;
private Integer periodicalid;
private double startdate;
private double enddate;
private Integer isfeeflagid;
private String remark;
private double optime;
private Integer opuserid;
private String opip;
private String r1;
private String r2;
private String r3;
private String r4;
private String r5; public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getPeopleid() {
return peopleid;
}
public void setPeopleid(Integer peopleid) {
this.peopleid = peopleid;
}
public String getPeoplename() {
return peoplename;
}
public void setPeoplename(String peoplename) {
this.peoplename = peoplename;
}
public Integer getServicestatusid() {
return servicestatusid;
}
public void setServicestatusid(Integer servicestatusid) {
this.servicestatusid = servicestatusid;
}
public Integer getFeespecialid() {
return feespecialid;
}
public void setFeespecialid(Integer feespecialid) {
this.feespecialid = feespecialid;
}
public double getChargefee() {
return chargefee;
}
public void setChargefee(double chargefee) {
this.chargefee = chargefee;
}
public Integer getPeriodicalid() {
return periodicalid;
}
public void setPeriodicalid(Integer periodicalid) {
this.periodicalid = periodicalid;
}
public double getStartdate() {
return startdate;
}
public void setStartdate(double startdate) {
this.startdate = startdate;
}
public double getEnddate() {
return enddate;
}
public void setEnddate(double enddate) {
this.enddate = enddate;
}
public Integer getIsfeeflagid() {
return isfeeflagid;
}
public void setIsfeeflagid(Integer isfeeflagid) {
this.isfeeflagid = isfeeflagid;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public double getOptime() {
return optime;
}
public void setOptime(double optime) {
this.optime = optime;
}
public Integer getOpuserid() {
return opuserid;
}
public void setOpuserid(Integer opuserid) {
this.opuserid = opuserid;
}
public String getOpip() {
return opip;
}
public void setOpip(String opip) {
this.opip = opip;
}
public String getR1() {
return r1;
}
public void setR1(String r1) {
this.r1 = r1;
}
public String getR2() {
return r2;
}
public void setR2(String r2) {
this.r2 = r2;
}
public String getR3() {
return r3;
}
public void setR3(String r3) {
this.r3 = r3;
}
public String getR4() {
return r4;
}
public void setR4(String r4) {
this.r4 = r4;
}
public String getR5() {
return r5;
}
public void setR5(String r5) {
this.r5 = r5;
} @Override
public String toString() {
return "Older [id=" + id + ", peopleid=" + peopleid + ", peoplename="
+ peoplename + ", servicestatusid=" + servicestatusid + ", feespecialid="
+ feespecialid + ", chargefee=" + chargefee + ", periodicalid=" + periodicalid
+ ", startdate=" + startdate + ", enddate=" + enddate + ", isfeeflagid=" + isfeeflagid
+ ", remark=" + remark + ", optime=" + optime + ", opuserid=" + opuserid
+ ", opip=" + opip + ", r1=" + r1 + ", r2=" + r2
+ ", r3=" + r3 + ", r4=" + r4 + ", r5=" + r5 + "]";
} public Older(Integer id, Integer peopleid, String peoplename, Integer servicestatusid,
Integer feespecialid, double chargefee, Integer periodicalid, double startdate,
double enddate, Integer isfeeflagid, String remark, double optime,
Integer opuserid, String opip, String r1, String r2,
String r3, String r4, String r5) {
super();
this.id = id;
this.peopleid = peopleid;
this.peoplename = peoplename;
this.servicestatusid = servicestatusid;
this.feespecialid = feespecialid;
this.chargefee = chargefee;
this.periodicalid = periodicalid;
this.startdate = startdate;
this.enddate = enddate;
this.isfeeflagid = isfeeflagid;
this.remark = remark;
this.optime = optime;
this.opuserid = opuserid;
this.opip = opip;
this.r1 = r1;
this.r2 = r2;
this.r3 = r3;
this.r4 = r4;
this.r5 = r5;
} }

Older.java

  jsp代码

   WebRoot目录下的三个jsp文件

   主页面:ajaxOperation.jsp

   

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%-- <%
response.setHeader("Content-Type","video/x-msvideo");
response.setHeader("Content-Disposition", "attachment;filename=aaa.doc");
response.header("content-type:application:json;charset=utf8");
response.header("Access-Control-Allow-Origin:*");
response.header("Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE");
response.header("Access-Control-Allow-Hefaders:x-requested-with,content-type");
%> --%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'ajaxOperation.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="jQuery/jquery-3.2.1.js"></script>
<script>
$(document).ready(
function() {
$.ajax({
url : "http://192.168.43.158:8080/TestSpringMVC/olders",
type : "POST",
dataType : "json",
success : function(data) {
$.each(data.rows, function (index, item) {
//循环获取数据
var id = item.id;
var peopleid = item.peopleid;
var peoplename = item.peoplename;
var servicestatusid = item.servicestatusid;
var feespecialid = item.feespecialid;
var chargefee = item.chargefee;
var periodicalid = item.periodicalid;
var startdate = item.startdate;
var enddate = item.enddate;
var isfeeflagid = item.isfeeflagid;
var remark = item.remark;
$("#peopleTable").html($("#peopleTable").html() + "<tr>"
+ "<td>"+ id + "</td>"+ "<td>"+ peopleid + "</td>"
+ "<td>"+ peoplename + "</td>" + "<td>"+ servicestatusid + "</td>"
+ "<td>"+ feespecialid + "</td>" + "<td>"+ chargefee + "</td>"
+ "<td>"+ periodicalid + "</td>" + "<td>"+ startdate + "</td>"
+ "<td>"+ enddate + "</td>" + "<td>"+ isfeeflagid + "</td>"
+ "<td>"+ remark + "</td>"
+ "<td>" + "<input type='button' value='删除' onclick='Delete("+id+")' />" + "</td>"
+ "<td>" + "<input type='button' value='修改' onclick='Update("+id+")' />" + "</td>"
+ "</tr>");
});
},
error : function() {
alert("数据访问错误");
}
});
}); //显示全部数据
function Show() {
$("#peopleTable").empty();
$("#peopleTable").html(
"<tr>" +
"<td>id</td>" +
"<td>peopleid</td>" +
"<td>peoplename</td>" +
"<td>servicestatusid</td>" +
"<td>feespecialid</td>" +
"<td>chargefee</td>" +
"<td>periodicalid</td>" +
"<td>startdate</td>" +
"<td>enddate</td>" +
"<td>isfeeflagid</td>" +
"<td>remark</td>" +
"<td>删除</td>" +
"<td>修改</td>" +
"</tr>");
$.ajax({
url : "http://192.168.43.158:8080/TestSpringMVC/olders",
type : "POST",
dataType : "json",
success : function(data) {
$.each(data.rows, function (index, item) {
//循环获取数据
var id = item.id;
var peopleid = item.peopleid;
var peoplename = item.peoplename;
var servicestatusid = item.servicestatusid;
var feespecialid = item.feespecialid;
var chargefee = item.chargefee;
var periodicalid = item.periodicalid;
var startdate = item.startdate;
var enddate = item.enddate;
var isfeeflagid = item.isfeeflagid;
var remark = item.remark;
$("#peopleTable").html($("#peopleTable").html() + "<tr>"
+ "<td>"+ id + "</td>"+ "<td>"+ peopleid + "</td>"
+ "<td>"+ peoplename + "</td>" + "<td>"+ servicestatusid + "</td>"
+ "<td>"+ feespecialid + "</td>" + "<td>"+ chargefee + "</td>"
+ "<td>"+ periodicalid + "</td>" + "<td>"+ startdate + "</td>"
+ "<td>"+ enddate + "</td>" + "<td>"+ isfeeflagid + "</td>"
+ "<td>"+ remark + "</td>"
+ "<td>" + "<input type='button' value='删除' onclick='Delete("+id+")' />" + "</td>"
+ "<td>" + "<input type='button' value='修改' onclick='Update("+id+")' />" + "</td>"
+ "</tr>");
});
},
error : function() {
alert("数据访问错误");
}
});
} //删除功能
function Delete(id) {
var oid = id;
if(confirm("确定要删除吗?")) {
$.ajax({
url : "http://192.168.43.158:8080/TestSpringMVC/older/delete",
data : {
"id":oid
},
});
alert("删除成功");
location.reload();
}
} //查询功能
function Search() {
var opeoplename = $("#searchInput").val();
$.ajax({
url : "http://192.168.43.158:8080/TestSpringMVC/older/search",
type : "POST",
dataType : "json",
data : {
"peoplename":opeoplename
},
success : function(data) {
$("#peopleTable").html(
"<tr>" +
"<td>id</td>" +
"<td>peopleid</td>" +
"<td>peoplename</td>" +
"<td>servicestatusid</td>" +
"<td>feespecialid</td>" +
"<td>chargefee</td>" +
"<td>periodicalid</td>" +
"<td>startdate</td>" +
"<td>enddate</td>" +
"<td>isfeeflagid</td>" +
"<td>remark</td>" +
"<td>删除</td>" +
"<td>修改</td>" +
"</tr>");
$.each(data.rows, function (index, item) {
//循环获取数据
var id = item.id;
var peopleid = item.peopleid;
var peoplename = item.peoplename;
var servicestatusid = item.servicestatusid;
var feespecialid = item.feespecialid;
var chargefee = item.chargefee;
var periodicalid = item.periodicalid;
var startdate = item.startdate;
var enddate = item.enddate;
var isfeeflagid = item.isfeeflagid;
var remark = item.remark;
$("#peopleTable").html($("#peopleTable").html() + "<tr>"
+ "<td>"+ id + "</td>"+ "<td>"+ peopleid + "</td>"
+ "<td>"+ peoplename + "</td>" + "<td>"+ servicestatusid + "</td>"
+ "<td>"+ feespecialid + "</td>" + "<td>"+ chargefee + "</td>"
+ "<td>"+ periodicalid + "</td>" + "<td>"+ startdate + "</td>"
+ "<td>"+ enddate + "</td>" + "<td>"+ isfeeflagid + "</td>"
+ "<td>"+ remark + "</td>"
+ "<td>" + "<input type='button' value='删除' onclick='Delete("+id+")' />" + "</td>"
+ "<td>" + "<input type='button' value='修改' onclick='Update("+id+")' />" + "</td>"
+ "</tr>");
});
},
error : function() {
alert("查询失败");
}
});
} //添加功能
function Add() {
window.location.href = "http://192.168.43.158:8080/TestSpringMVC/addWindow.jsp";
} //修改功能
function Update(id) {
var oid = id;
window.location.href = "http://192.168.43.158:8080/TestSpringMVC/updateWindow.jsp?id="+oid;
}
</script>
</head> <body>
<br>
请输入所查询的老人姓名:&nbsp;&nbsp;
<input type="text" id="searchInput" value=""/>
<input type="button" value="查询" id="searchButton" onclick="Search()"/>
<input type="button" value="添加老人" id="addButton" onclick="Add()"/>
<input type="button" value="显示全部数据" id="showButton" onclick="Show()"/>
<br><br>
<table id="peopleTable" border="1" cellpadding="10" cellspacing="0">
<tr>
<td>id</td>
<td>peopleid</td>
<td>peoplename</td>
<td>servicestatusid</td>
<td>feespecialid</td>
<td>chargefee</td>
<td>periodicalid</td>
<td>startdate</td>
<td>enddate</td>
<td>isfeeflagid</td>
<td>remark</td>
<td>删除</td>
<td>修改</td>
</tr>
</table>
</body>
</html>

ajaxOperation.jsp

   

   添加页面:addWindow.jsp  

   

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>添加界面</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head> <body>
<form action="http://192.168.43.158:8080/TestSpringMVC/older/add" method="POST">
id:<input type="text" name="id"><br>
peopleid:<input type="text" name="peopleid"><br>
peoplename:<input type="text" name="peoplename"><br>
servicestatusid:<input type="text" name="servicestatusid"><br>
feespecialid:<input type="text" name="feespecialid"><br>
chargefee:<input type="text" name="chargefee"><br>
periodicalid:<input type="text" name="periodicalid"><br>
startdate:<input type="text" name="startdate"><br>
enddate:<input type="text" name="enddate"><br>
isfeeflagid:<input type="text" name="isfeeflagid"><br>
remark:<input type="text" name="remark"><br>
<input type="submit" value="添加">
</form>
</body>
</html>

addWindow.jsp   

   修改页面:updateWindow.jsp

   

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>修改界面</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="jQuery/jquery-3.2.1.js"></script>
</head> <body>
<form action="http://192.168.43.158:8080/TestSpringMVC/older/update" method="POST">
<input type="hidden" name="id" value="<%=(String)request.getParameter("id") %>">
peopleid:<input type="text" name="peopleid"><br>
peoplename:<input type="text" name="peoplename"><br>
servicestatusid:<input type="text" name="servicestatusid"><br>
feespecialid:<input type="text" name="feespecialid"><br>
chargefee:<input type="text" name="chargefee"><br>
periodicalid:<input type="text" name="periodicalid"><br>
startdate:<input type="text" name="startdate"><br>
enddate:<input type="text" name="enddate"><br>
isfeeflagid:<input type="text" name="isfeeflagid"><br>
remark:<input type="text" name="remark"><br>
<input type="submit" value="确认修改" />
</form>
</body>
</html>

updateWindow.jsp

   

   注意!别忘在WebRoot目录下新建jQuery文件夹,放入jquery.js

   

  另外

   当时捣鼓如何连接数据库的时候建了个DB Brower,不知道用没用上,有时间我会弄明白它。(运行程序的时候,这个是未打开状态。)

   

   填坑:DB Browser类似于Navicat,但是相对操作要稍麻烦一些,好处是不用根据表写javabean了。

  查询功能效果界面

 删除功能效果界面

  

基于springmvc、ajax,后台连接数据库的增删改查的更多相关文章

  1. [译]聊聊C#中的泛型的使用(新手勿入) Seaching TreeVIew WPF 可编辑树Ztree的使用(包括对后台数据库的增删改查) 字段和属性的区别 C# 遍历Dictionary并修改其中的Value 学习笔记——异步 程序员常说的「哈希表」是个什么鬼?

    [译]聊聊C#中的泛型的使用(新手勿入)   写在前面 今天忙里偷闲在浏览外文的时候看到一篇讲C#中泛型的使用的文章,因此加上本人的理解以及四级没过的英语水平斗胆给大伙进行了翻译,当然在翻译的过程中发 ...

  2. MVC3+EF5.0 code first+Flexigrid+ajax请求+jquery dialog 增删改查

    MVC3+EF5.0 code first+Flexigrid+ajax请求+jquery dialog 增删改查 本文的目的:   1.MVC3项目简单配置EF code first生成并初始化数据 ...

  3. MVC3.0+knockout.js+Ajax 实现简单的增删改查

    MVC3.0+knockout.js+Ajax 实现简单的增删改查 自从到北京入职以来就再也没有接触MVC,很多都已经淡忘了,最近一直在看knockout.js 和webAPI,本来打算采用MVC+k ...

  4. 基于AT UI实现表格的增删改查遇到的坑

    基于AT UI实现表格的增删改查遇到的坑 坑一.表格数据加载的渲染报错 报错:Error in render: "TypeError: Cannot read property 'isChe ...

  5. SpringMVC框架下数据的增删改查,数据类型转换,数据格式化,数据校验,错误输入的消息回显

    在eclipse中javaEE环境下: 这儿并没有连接数据库,而是将数据存放在map集合中: 将各种架包导入lib下... web.xml文件配置为 <?xml version="1. ...

  6. ztree使用系列三(ztree与springmvc+spring+mybatis整合实现增删改查)

    在springmvc+spring+mybatis里整合ztree实现增删改查,上一篇已经写了demo,以下就仅仅贴出各层实现功能的代码: Jsp页面实现功能的js代码例如以下: <script ...

  7. 可编辑树Ztree的使用(包括对后台数据库的增删改查)

    找了很多网上关于Ztree的例子和代码才搞定. 首先,关于Ztree的代码不介绍了,网上下载之后,引用下列四个文件就能使用了. 1.关于配置选项.主要通过回调函数来实现向后台发送数据,实现增删改查. ...

  8. JDBC连接数据库及增删改查操作

    什么是JDBC?Java语言访问数据库的一种规范,是一套APIJDBC (Java Database Connectivity) API,即Java数据库编程接口,是一组标准的Java语言中的接口和类 ...

  9. 基于SSM之Mybatis接口实现增删改查(CRUD)功能

    国庆已过,要安心的学习了. SSM框架以前做过基本的了解,相比于ssh它更为优秀. 现基于JAVA应用程序用Mybatis接口简单的实现CRUD功能: 基本结构: (PS:其实这个就是用的Mapper ...

随机推荐

  1. 16. Ext.ux.TabCloseMenu插件的使用(TabPanel右键关闭菜单) 示例

    转自:https://crabdave.iteye.com/blog/327978 Ext.ux.TabCloseMenu插件的使用(TabPanel右键关闭菜单) 示例 效果: 创建调用的HTML: ...

  2. 2017年最新VOS2009/VOS3000最新手机号段导入文件(手机归属地数据)

    VOS2009.vos3000.vos5000最新手机号段归属地数据库导入文件. 基于2017年4月最新版手机号段归属地制作 共360569条记录,兼容所有版本的昆石VOS,包括VOS2009.vos ...

  3. hdu1213 并查集不压缩

    题意:题意:一个人请人吃饭,相互认识的朋友在一张桌子,相互认识的朋友的意思是如果A认识B,B认识C,那么A.B.C是朋友,对于每组输入输出桌子的张数. Sample Input 2 5 3 1 2 2 ...

  4. .gitignore(转载)

    转自:http://blog.csdn.net/liuqiaoyu080512/article/details/8648266 git 可以管理所有文件的变更, 但并不是所有文件都有意义. 大部分二进 ...

  5. bzoj 1611: [Usaco2008 Feb]Meteor Shower流星雨【BFS】

    t记录每个格子最早被砸的时间,bfs(x,y,t)表示当前状态为(x,y)格子,时间为t.因为bfs,所以先搜到的t一定小于后搜到的,所以一个格子搜一次就行 #include<iostream& ...

  6. bzoj1015星球大战(并查集+离线)

    1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 5572  Solved: 2563 Descri ...

  7. P3256 [JLOI2013]赛车

    传送门 如果把速度看成斜率,起始位置看成截距,这就是一个水平可见直线了-- 不过这题里我实现方法借鉴了CQzhangyu大佬的,先按速度排序,然后维护一个单调栈,如果当前的人速度比栈顶大距离又比它远直 ...

  8. 13、git

    安装Git 网上有很多Git安装教程,如果需要图形界面,windows下建议使用TortoiseGit,linux建议使用Git GUI或者GITK.(windows下载exe安装包,linux可以使 ...

  9. loadrunner乱码解决

    对于Virtual User Generator,本机编码方式为GB2312,GBK,GB18030,因此要修改为utf-8 1.录制过程产生的乱码解决方法: 在tool→recording opti ...

  10. [Qt Creator 快速入门] 第5章 应用程序主窗口

    对于日常见到的应用程序而言,许多都是基于主窗口的,主窗口中包含了菜单栏.工具栏.状态栏和中心区域等.这一章会详细介绍主窗口的每一个部分,还会涉及资源管理.富文本处理.拖放操作和文档打印等相关内容.重点 ...