一、今日学习内容:
人口普查系统:(18级学姐)
package dao; import Bean.Census; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import utils.JDBCUtils; import java.util.List; public class dao { JdbcTemplate template=new JdbcTemplate(JDBCUtils.getDataSource()); //添加 public boolean addCensus(Census census){ boolean flag=false; String sql="insert into census(hubie,housetype,area,housenum,holdername,idnum,gender,nation,education) values(?,?,?,?,?,?,?,?,?)"; int update = template.update(sql, census.getHubie(), census.getHousetype(), census.getArea() , census.getHousenum(), census.getHoldername(), census.getIdnum() , census.getGender(), census.getNation(), census.getEducation()); if (update>=1){ //update表示操作成功的数目,大于等于1时添加成功 flag=true; } return flag; } //修改 public boolean updateCensus(Census census){ boolean flag=false; String sql="update census set hubie=?,housetype=?,area=?,housenum=?,holdername=?,idnum=?" + ",gender=?,nation=?,education=? where id=?"; int update = template.update(sql, census.getHubie(),census.getHousetype(),census.getArea(),census.getHousenum() ,census.getHoldername(),census.getIdnum(),census.getGender(),census.getNation(),census.getEducation(),census.getId()); if (update>=1){ flag=true; } return flag; } //删除 public boolean delCensus(int id){ boolean flag=false; String sql="delete from census where id=?"; int update = template.update(sql, id); if (update>=1){ flag=true; } return flag; } //查询全部 public List<Census> queryAll(){ String sql="select * from census order by id desc"; List<Census> censusList = template.query(sql, new BeanPropertyRowMapper<Census>(Census.class)); return censusList; } //根据姓名查询 public Census queryByName(String name){ String sql="select * from census where holdername=?"; Census censuse = template.queryForObject(sql, new BeanPropertyRowMapper<Census>(Census.class), name); return censuse; } //根据id查询 public Census queryById(int id){ String sql="select * from census where id=?"; Census censuse = template.queryForObject(sql, new BeanPropertyRowMapper<Census>(Census.class), id); return censuse; } //模糊查询 public List<Census> search(String sql,String stj){ List<Census> censuses = template.query(sql, new BeanPropertyRowMapper<>(Census.class), stj); return censuses; } }
<%-- Created by IntelliJ IDEA. User: 张志伟 Date: 2020/11/12 Time: 17:07 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>主页</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="${pageContext.request.contextPath }/bootstrap/css/bootstrap.min.css"> <script src="${pageContext.request.contextPath }/bootstrap/js/jquery-3.5.1.min.js"></script> <script src="${pageContext.request.contextPath }/bootstrap/js/bootstrap.min.js"></script> </head> <body> <!--导航栏--> <nav class="navbar navbar-inverse"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">人口普查登记 <small>V1.0</small></a> </div> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> </nav> <!--导航栏--> <!--页面中心内容--> <div class="container-fluid"> <div class="row"> <!--左半区--> <div class="col-sm-2"> <!--菜单组件--> <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> <div class="panel panel-default"> <div class="panel-heading" role="tab" id="headingOne"> <h4 class="panel-title"> <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne"> 菜单 </a> </h4> </div> <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne"> <div class="panel-body"> <ul class="list-group"> <a class="list-group-item active" href="index.jsp">信息登记</a> <a class="list-group-item"href="queryAllServlet">信息浏览</a> <a class="list-group-item"href="search.jsp">模糊查询</a> </ul> </div> </div> </div> </div> </div> <!--左半区--> <!--中间部分--> <div id="content"> <!--页面中心内容--> <div class="col-sm-10"> <form action="${pageContext.request.contextPath}/addCensusServlet" method="post" onsubmit="return check()"> <script> function check() { var area=$("#area").val().trim(); var housenum=$("#housenum").val().trim(); var idnum = $("#idnum").val().trim(); var isCardNo = function (card) { //身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/; return reg.test(card); }; var check = /^\d+$/; if(area == null || isNaN(area) || area == "" || !check.test(area)){ alert("房间面积为整数") return false; } if(housenum == null || isNaN(housenum) || housenum == "" || !check.test(housenum)){ alert("房间个数为整数"); $("#housenum").focus(); return false; } if (!isCardNo(idnum)){ alert("请输入正确的身份证号") return false; } } </script> <table id="addTable" class="table table-bordered "> <tr class="text-center row"> <td class="col-sm-2"> 户别 </td> <td class="col-sm-4"> <input type="radio" name="hubie" id="hubie1" value="家庭户">家庭户 <input type="radio" name="hubie" id="hubie2" value="集体户">集体户 </td> <td class="col-sm-2"> 住房类型 </td> <td class="col-sm-4"> <input type="radio" name="housetype" id="housetype1" value="家庭住宅">家庭住宅 <input type="radio" name="housetype" id="housetype2" value="集体住所">集体住所 <input type="radio" name="housetype" id="housetype3" value="工作地住所">工作地住所 <input type="radio" name="housetype" id="housetype4" value="其他住宅">其他住宅 <input type="radio" name="housetype" id="housetype5" value="无住宅">无住宅 </td> </tr> <tr class="text-center row"> <td class="col-sm-2"> 本户现住房面积 </td> <td class="col-sm-4"> <input type="text" class="form-control" name="area" id="area" placeholder="请输入数字(平方米)"> </td> <td class="col-sm-2 "> 本户现住房间数 </td> <td class="col-sm-4"> <input type="text" class="form-control" name="housenum" id="housenum" placeholder="请输入数字(间)"> </td> </tr> <tr class="text-center row"> <td class="col-sm-2"> 户主姓名 </td> <td class="col-sm-4"> <input type="text" class="form-control" name="holdername" id="holdername" placeholder="请输入户主姓名"> </td> <td class="col-sm-2 "> 身份证号码 </td> <td class="col-sm-4"> <input type="text" class="form-control" name="idnum" id="idnum" placeholder="请输入身份证号码"> </td> </tr> <tr class="text-center row"> <td class="col-sm-2"> 性别 </td> <td class="col-sm-4"> <input type="radio" name="gender" id="gender1" value="男">男 <input type="radio" name="gender" id="gender2" value="女">女 </td> <td class="col-sm-2"> 民族 </td> <td class="col-sm-4"> <input type="text" class="form-control" name="nation" id="nation" placeholder="民族"> </td> </tr> <tr class="text-center row"> <td> 受教育程度 </td> <td colspan="3"> <select class="form-control" id="education" name="education"> <option value="研究生">研究生</option> <option value="大学本科">大学本科</option> <option value="大学专科">大学专科</option> <option value="高中">高中</option> <option value="初中">初中</option> <option value="小学">小学</option> <option value="未上过学">未上过学</option> </select> </td> </tr> </table> <button type="submit" class="btn btn-info col-sm-offset-6">提交</button> </form> <%--出错显示的信息框--%> <div id="register_msg_alert" class="alert alert-warning alert-dismissible hide" role="alert"> <button type="button" class="close" data-dismiss="alert" > <span >x</span> </button> <strong>${add_msg}</strong> </div> </div> </div> </div> </div> <!--页面中心内容--> </body> </html>
二、遇到的问题:
关于servlet还是不太明白。
三、明日学习计划:
继续学习javaweb。