目录

负载均衡式的在线OJ项目编写四

负载均衡式的在线OJ项目编写(四)

一.前期内容回顾

对前面的准备不熟悉的,可以看前面的内容,连接如下:

二.view模块编写和control模块编写

下面涉及到前后端联动的开发

contrl模块代码实现

#pragma once


#include <iostream>
#include <string>
#include <vector>

#include "../comm/util.hpp"
#include "../comm/log.hpp"
#include "oj_model.hpp"
#include "oj_view.hpp"

namespace ns_control
{
    using namespace std;
    using namespace ns_log;
    using namespace ns_util;
    using namespace ns_model;
    using namespace ns_view;
    class Control
    {
    private:
        Model model_; //提供后台数据
        View view_;   //提供html渲染功能
    public:
        Control()
        {

        }

        ~Control()
        {

        }

        //根据题目数据构建网页
        bool AllQuestions(std::string *html)
        {
            bool ret = true;
            vector<Question> all;
            if(model_.GetAllQUestions(&all))
            {
                //获取一个题目信息成功,将所有的题目数据构建成网页
                view_.AllExpandHtml(all,html);
            }
            else
            {
                *html = "获取题目失败,形成题目列表失败";
                ret = false;
            }
            return ret;
        }

        bool OneQuestion(const string& number,string* html)
        {
            bool ret = true;
            Question q;
            if(model_.GetOneQUestion(number,&q))
            {
                //获取指定题目信息成功,将所有的题目数据构建成网页
                view_.OneExpandHtml(q,html);
            }
            else
            {
                *html = "指定题目: " + number + " 不存在!";
                ret = false;
            }
            return ret;
        }
    };
}

https://i-blog.csdnimg.cn/direct/4ccfd8bc70494ba7b798cfd19ec955b5.png

现在我们要写html文件(推荐一个网站)

我们在呈现题目的时候,推荐使用表格

https://i-blog.csdnimg.cn/direct/d5aae8980ca441008943d4b0740b04cf.png

<table>
        <tr>
            <th>题目编号</th>
            <th>题目标题</th>
            <th>题目难度</th>
        </tr>
        <tr>
            <td>111</td>
            <td>222</td>
            <td>333</td>
        </tr>
        <tr>
            <td>111</td>
            <td>222</td>
            <td>333</td>
        </tr>
        <tr>
            <td>111</td>
            <td>222</td>
            <td>333</td>
        </tr>
    </table>

展示效果

https://i-blog.csdnimg.cn/direct/8dab2535fecc45afb7136ff97d67b3f6.png

实现网页跳转的功能

https://i-blog.csdnimg.cn/direct/a532b11d09294ab7b70f086dec875971.png

https://i-blog.csdnimg.cn/direct/c5fd302157f1422da9ff3c07f9e23fac.png

https://i-blog.csdnimg.cn/direct/1f069ea482d1460ca2f4a8e93a790a17.png

如果后续引⼊了ctemplate,⼀旦对⽹⻚结构进⾏修改,尽量的每次想看到结果,将server重启⼀ 下。ctemplate有⾃⼰的优化加速策略,可能在内存中存在缓存⽹⻚数据(old)

https://i-blog.csdnimg.cn/direct/c43ccc09f17b413e97f5e643713cfff7.png

https://i-blog.csdnimg.cn/direct/bb81bfdc00004c508ba7ef897a777750.png

将这个标题啥的全部显示,