service.js

//引入http模块
const http = require('http');
//创建网站服务器
const app = http.createServer();const template = require('art-template');
const path = require('path');
const serveStatic = require('serve-static');//静态资源服务
const serve = serveStatic(path.join(__dirname));const dateformat = require('dateformat');
const route = require('./index.js');template.defaults.imports.dateformat = dateformat;
//配置模板根目录
template.defaults.root = path.join(__dirname);//实现学生信息添加
//router
require('./connect.js')app.on('request', (req, res) => {router(req, res, () => {})serve(req, res, () => {})
});app.listen(3000);
console.log('服务器启动成功');

index.js

//引入路由
const getRouter = require('router');
const router = getRouter();
const Student = require('./user.js')
const template = require('art-template');
const querystring = require('querystring');
router.get('/add', (req, res) => {/* res.end('test') */let html = template('index.art', {});res.end(html);
})
router.get('/list', async(req, res) => {//查询用户信息let students = await Student.find();console.log(students);let html = template('list.art', {students: students});res.end(html);
})
router.post('/add', (req, res) => {let formData = '';req.on('data', param => {formData += param;});req.on('end', async() => {await Student.create(querystring.parse(formData));res.writeHead(301, {Location: '/list'});res.end();})
});
module.exports = router;
//实现学生信息添加

user.js

const mongoose = require('mongoose');const studentsSchema = new mongoose.Schema({name: {type: String,required: true,minlength: 2,maxlength: 10},age: {type: Number,min: 10,max: 25},sex: {type: String},email: String,hobbies: [String],collage: String,enterDate: {type: Date,default: Date.now}});
const Student = mongoose.model('Student', studentsSchema);module.exports = Student;

connect.js

//链接数据库
const mongoose = require('mongoose');
//链接数据库
mongoose.connect('mongodb://localhost/playground', { useNewUrlParser: true }).then(() => console.log('数据库安装成功')).catch(() => console.log('数据库链接失败'))

index.artlis

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"><title>学生档案</title><link rel="stylesheet" href="./main.css">
</head>
<body><form action="/add" method="post"><fieldset><legend>学生档案</legend><label>姓名: <input class="normal" type="text" autofocus placeholder="请输入姓名" name="name"></label><label>年龄: <input class="normal"  type="text" placeholder="请输入年龄" name="age"></label><label>性别: <input type="radio" value="0" name="sex"> 男<input type="radio" value="1" name="sex"> 女</label><label>邮箱地址: <input class="normal" type="text" placeholder="请输入邮箱地址" name="email"></label><label>爱好: <input type="checkbox" value="敲代码" name="hobbies"> 敲代码<input type="checkbox" value="打篮球" name="hobbies"> 打篮球<input type="checkbox" value="睡觉" name="hobbies"> 睡觉</label><label>所属学院: <select class="normal" name="collage"><option value="前端与移动开发">前端与移动开发</option><option value="PHP">PHP</option><option value="JAVA">JAVA</option><option value="Android">Android</option><option value="IOS">IOS</option><option value="UI设计">UI设计</option><option value="C++">C++</option></select></label><label>入学日期: <input type="date" class="normal" name="enterDate"></label><label class="btn"><input type="submit" value="提交" class="normal"></label></fieldset></form>
</body>
</html>

list.art

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>学员信息</title><link rel="stylesheet" href="./list.css">
</head>
<body><table><caption>学员信息</caption><tr><th>姓名</th><th>年龄</th><th>性别</th><th>邮箱地址</th><th>爱好</th><th>所属学院</th><th>入学时间</th></tr>{{each students}}<tr><th>{{$value.name}}</th><th>{{$value.age}}</th><th>{{$value.sex == '0' ? '男' : '女'}}</th><th>{{$value.email}}</th><th>{{each $value.hobbies}}<span>{{$value}}</span>{{/each}}</th><th>{{$value.collage}}</th><th>{{dateformat($value.enterDate, 'yyyy-mm-dd')}}</th></tr>{{/each}}</table>
</body>
</html>

main.css


body {margin: 0;padding: 0 0 40px;background-color: #F7F7F7;font-family: '微软雅黑';
}form {max-width: 640px;width: 100%;margin: 24px auto;font-size: 28px;
}label {display: block;margin: 10px 10px 15px;font-size: 24px;
}.normal {display: block;width: 100%;height: 40px;font-size: 22px;margin-top: 10px;padding: 6px 10px;color: #333;border: 1px solid #CCC;box-sizing: border-box;
}.btn {margin-top: 30px;
}.btn input {color: #FFF;background-color: green;border: 0 none;outline: none;cursor: pointer;
}input[type="file"] {/*opacity: 0;*/width: 120px;position: absolute;right: 0;z-index: 9;
}.import {height: 40px;position: relative;
}

list.css


body {margin: 0;padding: 0 0 40px;background-color: #F7F7F7;font-family: '微软雅黑';
}form {max-width: 640px;width: 100%;margin: 24px auto;font-size: 28px;
}label {display: block;margin: 10px 10px 15px;font-size: 24px;
}.normal {display: block;width: 100%;height: 40px;font-size: 22px;margin-top: 10px;padding: 6px 10px;color: #333;border: 1px solid #CCC;box-sizing: border-box;
}.btn {margin-top: 30px;
}.btn input {color: #FFF;background-color: green;border: 0 none;outline: none;cursor: pointer;
}input[type="file"] {/*opacity: 0;*/width: 120px;position: absolute;right: 0;z-index: 9;
}.import {height: 40px;position: relative;
}

运行结果

前端学习(1364):学生档案信息管理6相关推荐

  1. 前端学习(1363):学生档案信息管理5

    service.js //引入http模块 const http = require('http'); //创建网站服务器 const app = http.createServer(); //引入路 ...

  2. 前端学习(1362):学生档案信息管理4

    service.js //引入http模块 const http = require('http'); //创建网站服务器 const app = http.createServer(); //引入路 ...

  3. 前端学习(1361):学生档案信息管理3

    service.js //引入http模块 const http = require('http'); //创建网站服务器 const app = http.createServer(); //引入路 ...

  4. 学生档案信息管理之模板引擎的应用

    实现学生信息添加功能  在模板的表单中指定请求地址与请求方式  为每一个表单项添加name属性  添加实现学生信息功能路由  接收客户端传递过来的学生信息  将学生信息添加到数据库中  将页面重定向到 ...

  5. 前端学习(1360) :学生档案信息管理2

    service.js //引入http模块 const http = require('http'); //创建网站服务器 const app = http.createServer(); //引入路 ...

  6. 前端学习(1359) :学生档案信息管理1

    \ service.js //引入http模块 const http = require('http'); //创建网站服务器 const app = http.createServer(); // ...

  7. Python高校学生档案管理系统毕业设计源码071528

    Python高校学生档案管理系统 摘 要 随着互联网趋势的到来,各行各业都在考虑利用互联网将自己推广出去,最好方式就是建立自己的互联网系统,并对其进行维护和管理.在现实运用中,应用软件的工作规则和开发 ...

  8. 基于java实现的学生档案管理系统毕业论文(可下载)

    目录 摘    要 学生档案管理系统是当今互联网时代下的趋势和不可缺少的一部分,他可以高效快速的完成和解决信息的查询和录入.随着计算机的快速发展和普及,越来越多的办公离不开电脑. 本系统采用B/S模式 ...

  9. MongoDB+模板引擎 项目学习 ---学生档案管理

    MongoDB+模板引擎 项目学习 -学生档案管理 1 案例介绍 目标:模板引擎应用,强化node.js项目制作流程 知识点:http请求响应.数据库.模板引擎.静态资源访问 ​ 项目效果展示 2 制 ...

最新文章

  1. 高可用集群技术之heartbeat应用详解(一)
  2. SpringMVC的请求-文件上传-多文件上传的代码实现
  3. 了解LSTM和GRU
  4. CSS计数器(自定义列表)
  5. api文档数据量太大崩溃_Tableau的API操作(一)-取消任务刷新
  6. P50发布!网友:滚筒洗衣机也能打电话了
  7. android版本迭代,多盟:android2.3仍是主流 iOS新版本迭代加
  8. 系统服务启动交互式程序(C++)
  9. 机器学习之问题建模(一)
  10. 2022新和平精英画质助手iApp源码+附成品/可用的
  11. 游戏反编译工具dnSpy
  12. Windows终端配置emoji
  13. 如何破解锐捷支持多网卡
  14. 求四边形最大内接矩形,一种不规则多边形的最大内接矩形的快速近似求解方法与流程...
  15. 手机号码测凶吉附带手机号码归属地C#版
  16. Serializable接口分析
  17. 5G-SUPI-SUPC-IMSI
  18. ES聚合Aggregation---原生(restful)api
  19. php短网址生成原理,php 生成短网址原理及代码
  20. Hadoop学习之环境搭建和解决方案

热门文章

  1. javascript 点点滴滴01章 javascript的认知
  2. 利用FPGA加速实现高性能计算
  3. Python3.2官方文档翻译--作用域和命名空间
  4. 疑难杂症--由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作
  5. GIS数据里的4D数据
  6. [导入]C#中TextBox只能输入数字的代码
  7. php 公钥格式转换,如何把OpenSSH公钥转换成OpenSSL格式
  8. 弹出框 每次打开 滚动条置顶_微信置顶文字怎么弄?微信置顶一句话教程
  9. redhat6 删除mysql_Red Hat enterprise linux 6卸载默认安装的 mysql
  10. linux path环境变量起什么作用,shell基础(5)PATH环境变量的作用和使用方法