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

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;
}

运行结果

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/420141.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

lua元表(简单例子)

Set {} Set.mt {}--定义普通的表作为元表&#xff0c;为了避免命名污染直接放在Set内部 function Set.new(t)local set {}setmetatable(set, Set.mt)--一组相关的表共享一个metatable(通过这个可以描述他们共同的行为)&#xff0c;一个表也可以是自身的metatable(描述私有行…

java windows7 环境变量_Windows7环境变量中,系统变量与用户变量的优先级

就我理解&#xff0c;不存在先后区别。因为系统变量和用户变量完全不是一回事情&#xff0c;因此某个用户登录他的账户&#xff0c;并且启用了用户变量&#xff0c;那么它会先检查用户变量&#xff0c;如果没有检查到就检查系统变量&#xff0c;都没有则报错。如果按照这样的理…

前端学习(1389):多人管理项目9登录功能具体实现

blog.js const express require(express); //创建网站服务器 const app express(); //开放静态资源文件 const path require(path); require(./model/connect)//告诉express框架模板所在的位置 app.set(views, path.join(__dirname, views)); //告诉express框架模板的后缀是…

英语常见介词错误用法,你有犯过吗?

英语常见介词错误用法&#xff0c;你有犯过吗&#xff1f; 1:错:come to here. 对:come here. 过来。here ,there,home之类的副词&#xff0c;前面不用介词in ,at,(但可以加from,比如from home,from here),直接跟在动词come 后面就可以了。2:错:look at the mirror. 对:look in…

java弹出提示窗口_Java实现弹窗效果的基本操作(2)

本文为大家分享了Java实现弹窗效果的实现代码&#xff0c;供大家参考&#xff0c;具体内容如下1、任务简介我在5月23日写过一篇文章为《Java弹窗操作》&#xff0c;从目前来看浏览量不错&#xff0c;故我将之前省略了的两个程序分享出来&#xff0c;同时也将更多的方法分享出来…

前端学习(1390):多人管理项目10服务器认证

blog.js const express require(express); //创建网站服务器 const app express(); //开放静态资源文件 const path require(path); require(./model/connect)//告诉express框架模板所在的位置 app.set(views, path.join(__dirname, views)); //告诉express框架模板的后缀是…

C# 控制台或者winform程序开启http的监听状态

1 public class THttpListener2 {3 HttpListener listerner;4 /// <summary>5 /// 6 /// </summary>7 /// <param name"prefixes">格式 http://*/test/ </param>8 /// <param name&…

前端学习(1391):多人管理项目11邮箱地址查询信息

blog.js //管理页面 //展示页面 const express require(express);const admin express.Router();admin.get(/login, (req, res) > {res.render(admin/login) }); admin.get(/user, (req, res) > {res.render(admin/user) }); admin.post(/login, async(req, res) >…

java tea属于红茶吗_什么茶属于红茶类

茶叶在中国的历史已经非常悠久了。相信很多人都喝过红茶&#xff0c;红茶种类还是比较多的&#xff0c;那么知道什么茶属于红茶类吗&#xff1f;平时买回来的红茶该怎么保存比较好呢&#xff1f;什么茶属于红茶类 1、中国的红茶种类还是比较多的。其中滇红&#xff0c;祁红&…

前端学习(1392):多人管理项目12加密

blog.js //管理页面 //展示页面 const express require(express);const admin express.Router();admin.get(/login, (req, res) > {res.render(admin/login) }); admin.get(/user, (req, res) > {res.render(admin/user) }); admin.post(/login, async(req, res) >…

【c++ primer读书笔记】【第2章】变量和基本类型

1、 无符号类型 含有无符号类型的表达式&#xff0c;当一个算式表达式中既有unsigned int&#xff0c;又有int时&#xff0c;int会转化为unsigned int&#xff0c; 如int a-1&#xff0c;unsigned b1&#xff0c;则在我的机器中a*b4294967295。 无符号数不会小于0也关系到循环…

java 注入 循环_spring依赖注入——循环依赖

上一篇博客简单地分析了下依赖注入。但是对于依赖注入的很多细节&#xff0c;都没有深入的分析。这一篇博客会继续分析spring的依赖注入。这篇博客会解决分析getBean缓存时候遗留下来的循环依赖问题。循环依赖分析首先明确下&#xff0c;只有单例情况下&#xff0c;spring才会试…

前端学习(1393):多人管理项目13加密实现

blog.js //管理页面 //展示页面 const express require(express);const admin express.Router();admin.get(/login, (req, res) > {res.render(admin/login) }); admin.get(/user, (req, res) > {res.render(admin/user) }); admin.post(/login, async(req, res) >…

Python的逻辑运算符and小析

近期突然对验证码的识别感兴趣了,然后就研究了一些图像识别和处理的资料,其中有一种图像处理是关于字体的细化和骨架提取的,但是这种算法没有现成的java代码实现,那些号称的java版代码多半都是效果很差或是根本不行的..搜索的途中看到一个用python实现的细化提骨架算法,效果很不…

java二叉树的深度_java 二叉树的最大深度

二叉树的最大深度Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no children.Example:Given binary tree [3,9,20,null,nul…

前端学习(1394):多人管理项目14多人加密使用

users.js // 创建用户集合 // 引入mongoose第三方模块 const mongoose require(mongoose); // 导入bcrypt const bcrypt require(bcrypt); // 引入joi模块 const Joi require(joi); // 创建用户集合规则 const userSchema new mongoose.Schema({username: {type: String,r…

【卡法电子商务】-常用手机屏幕尺寸 ★★★★★

iPhone4/iPhone4s 320 * 372 / 320 * 441 (已隐藏URL与状态栏) iPhone5/iPhone5s 320 * 460 / 320 * 529 (已隐藏URL与状态栏) Note2 360 * 567 (未隐藏URL与状态栏) iPad 3/4 768*928 (未隐藏URL与状态栏) GALAXY SIII 360 * 567 (未隐藏URL与状态栏) 小米2A 360…

java提高篇四_(转)java提高篇(四)-----理解java的三大特性之多态

面向对象编程有三大特性&#xff1a;封装、继承、多态。封装隐藏了类的内部实现机制&#xff0c;可以在不影响使用的情况下改变类的内部结构&#xff0c;同时也保护了数据。对外界而已它的内部细节是隐藏的&#xff0c;暴露给外界的只是它的访问方法。继承是为了重用父类代码。…

前端学习(1395):多人管理项目15建立请求

{{extend ./common/layout.art}}{{block main}}<!-- 子模板的相对路径相对的就是当前文件 因为它是由模板引擎解析的 而不是浏览器 -->{{include ./common/header.art}}<!-- 主体内容 --><div class"content">{{include ./common/aside.art}}<d…

CreateProcess的使用方法

使用编译器vs2008。 第一、第二个參数的使用方法&#xff1a; 样例&#xff1a; 使用ie打开指定的网页。 注意第二个參数是 可运行文件命令行參数 #include "stdafx.h" #include <windows.h> #include <stdio.h> int main(int argc, char* argv[]) { STA…