新闻发布系统

① 首页为index这里将列出所有新闻类型以及对于新闻条目

② 各个新闻条目拥有编辑/删除/查看 三个按钮

③ 首页具有增加新闻按钮(增加时候可上传图片)

基本功能如上

于是,我们去掉app里面的路由功能,将路由全部放到index里面

//将路由功能放入index
//app.get('/', routes.index);
//app.get('/users', user.list);
routes(app);
复制代码
module.exports = function (app) {
  //主页,现在也是首页
  app.get('/', function (req, res) {
    res.render('index', { title: 'Express' });
  });

  app.get('/add', function (req, res) {
    res.send('增加新闻请求');
  });

  app.get('/delete', function (req, res) {
    res.send('删除新闻请求');
  });

  app.get('/view', function (req, res) {
    res.send('查看新闻请求');
  });

  app.get('/update', function (req, res) {
    res.send('修改新闻请求');
  });

};
复制代码

第一步简单如此,因为增加新闻应该有单独的页面,而具体点击增加按钮又会有其他处理,所以内部还得细分各个请求,现在规定如下:

/ 默认页面,该页面显示所有类型以及新闻,并带有删除按钮

/add 进入添加新闻页面

/addNews 添加新闻具体post请求地址(点击按钮时候的响应)

/delete 删除新闻请求

/view 具体新闻查询

于是稍微修改下上述路由:

复制代码
module.exports = function (app) {
  //主页,现在也是首页
  app.get('/', function (req, res) {
    res.render('index', { title: 'Express' });
  });

  app.get('/add', function (req, res) {
    res.send('添加新闻页面');
  });

  app.post('/addNews', function (req, res) {
    res.send('处理添加新闻请求');
  });

  app.get('/delete', function (req, res) {
    res.send('删除新闻请求');
  });

  app.get('/view', function (req, res) {
    res.send('查看新闻请求');
  });

};
复制代码

于是我们需要新建几个模板组织我们的网页,这里我们先不分离头尾只要最简单的页面即可

新增add与view两个模板文件,暂时表现与index.ejs一致,并且修改导航相关

复制代码
module.exports = function (app) {
  //主页,现在也是首页
  app.get('/', function (req, res) {
    res.render('index', { title: 'Express' });
  });

  app.get('/add', function (req, res) {
    res.render('add', { title: '添加新闻页面' });
  });

  app.post('/addNews', function (req, res) {
    res.send('处理添加新闻请求');
  });

  app.get('/delete', function (req, res) {
    res.send('删除新闻请求');
  });

  app.get('/view', function (req, res) {
    res.render('view', { title: '查看新闻请求' });

  });
};
posted @ 2017-04-24 11:29  呵呵哒12138  阅读(314)  评论(0编辑  收藏  举报