电子公文传输系统——bootstrap+mysql

布局使用bootstrapUI库

对于前端设计来说,bootstrap是极流行、便捷的设计框架,有丰富的UI库甚至可视化设计工具。

读者可自行前往菜鸟教程搜索学习。

建立数据库

根据需求,建立数据库

用一个java类实现对数据库的连接

以下展示主要的类方法,访问对应的MySQL服务器实现对数据库的连接。

public static Connection getConn(){
        try{
        	Class.forName(dbDriver).newInstance(); 
        	Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/##yoursDBname##?user=root&password=##yoursPASSWORD##&useUnicode=true&characterEncoding=GBK");
//        	Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/northwind","root","123");
 //       	Connection conn=DriverManager.getConnection("jdbc:odbc:twtweb");
            return conn;
        }catch(Exception ex){
            ex.printStackTrace();
            return null;
        }
    }

利用mysql语句执行对库的操作

以项目中注册的功能为例,展示一个核心类方法。

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=gb2312");
		request.setCharacterEncoding("gb2312");

		CRUDHelper ib = new CRUDHelper();
		String name = request.getParameter("name");
		String pwd = request.getParameter("pwd");
		String type = request.getParameter("type");
		String enabled = request.getParameter("enabled");
		String type1 = request.getParameter("type1");
		String sql = "";
		if (type.equals("1")) {
			sql = "insert into admin(name,pwd,type,status,enpwd,enabled) values('" + name + "','" + pwd + "','" + type
					+ "','管理员','" + SM2.encrypt(pwd) + "','" + enabled + "')";
		} else if (type.equals("2")) {
			sql = "insert into admin(name,pwd,type,status,enpwd,enabled) values('" + name + "','" + pwd + "','" + type
					+ "','拟稿人','" + SM2.encrypt(pwd) + "','" + enabled + "')";
		} else if (type.equals("3")) {
			String status = request.getParameter("status");
			sql = "insert into admin(name,pwd,type,status,enpwd,enabled) values('" + name + "','" + pwd + "','" + type
					+ "','" + status + "','" + SM2.encrypt(pwd) + "','" + enabled + "')";
		}
		int responseText = ib.insertANDupdateANDdel(sql);
		if (responseText == -1) {
			request.setAttribute("message", "'用户名重复!'");
		} else {
			request.setAttribute("message", "'操作成功!'");
		}
		if (type1 == null || type1.equals(""))
			request.getRequestDispatcher("/admin/systemuser.jsp").forward(request, response);
		else
			response.sendRedirect("/gwlzxt/admin/login.jsp");
	}
posted @ 2022-12-11 17:33  你先别急队  阅读(74)  评论(0编辑  收藏  举报