Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop user background Management system with Java

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, the editor will share with you the relevant knowledge points about how to develop a user background management system with Java. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.

Main function

Administrator login function, administrator list operation, user list operation, order management

Login function

Design idea: the front-end page gets the input data, then sends the Ajax request, obtains the data in servlet and calls the method in the service layer to deal with it, the service layer calls the implementation method of the dao layer, and finally servlet returns a result set to judge whether the login is successful or not.

Main function codes of login.html:

(function () {$("# btn_login") .click (function () {/ / get data let username = $("# username") .val (); let password = $("# password") .click () / / data processing $.post ("admin/login", {username: username, password: password}, function (result) {if (result.flag) {location.href = "index.html";} else {alert (result.errorMsg);}}) );})

Function codes in servlet:

/ / Log in to public void login (HttpServletRequest request, HttpServletResponse response) throws ServletException, and IOException {/ / get the username and password String username = request.getParameter ("username"); String password = request.getParameter ("password"); / / encapsulate the administrator object Administrator admin = new Administrator (); admin.setAname (username); admin.setPassword (password) / / create the result object ResultInfo resultInfo = new ResultInfo (); / / call service query Administrator administrator = service.login (admin); if (administrator = = null) {resultInfo.setFlag (false); resultInfo.setErrorMsg ("wrong username or password!") ;} if (administrator! = null & &! administrator.getStatus (). Equals ("Y")) {resultInfo.setFlag (false); resultInfo.setErrorMsg ("this account is not activated!") ;} if (administrator! = null & & administrator.getStatus (). Equals ("Y")) {resultInfo.setFlag (true); / / set session request.getSession () .setAttribute ("username", administrator.getAname ());} / / call the method defined in the parent class, transfer json data and return writeValue (resultInfo, response);}

Code implementation in the service layer:

@ Override public Administrator login (Administrator administrator) {return dao.login (administrator);}

Code implementation in the dao layer:

@ Override public Administrator login (Administrator administrator) {Administrator admin = null; try {String sql = "SELECT * FROM administrator WHERE aname =? AND PASSWORD =?"; admin = template.queryForObject (sql, new BeanPropertyRowMapper (Administrator.class), administrator.getAname (), administrator.getPassword ());} catch (Exception e) {} return admin;}

Achieve results:

List of administrators

Design idea: data operation and login functions are more or less the same, to achieve the addition, deletion, modification and query of the administrator, this paper focuses on paging and fuzzy query.

Main function codes of admin_list.html:

(function () {let name = null; $("# btn_search") .click (function () {name = $('# admin_name'). Val (); the default jump behavior of the load (null, name) / / cancel button causes the page return false to be refreshed ) load (null, name);}) Function load (currentPage, admin_name) {/ / send ajax request, request route/pageQuery, pass cid $.get ("admin/pageQuery", {currentPage: currentPage, admin_name: admin_name}, function (pb) {/ / definition character let lis = "") / / calculate the page number of the previous page let beforeNum = pb.currentPage-1; if (beforeNum pb.totalPage) {end = pb.totalPage; begin = end-9 }} / / display the page number for (let I = begin; I = pb.totalPage) {nextNum = pb.totalPage;} let nextPage ='> >'; lis + = nextPage / / set the lis content to ul $("# pageNum") .html (lis); / / list data display let admin_lis = "; for (let I = 0; I)

< pb.list.length; i++) { let admin = pb.list[i]; let li; if (admin.status === "Y") { li = '\n' + ' \n' + ' \n' + ' ' + ' \n' + ' ' + admin.aid + '\n' + ' ' + admin.aname + '\n' + ' ' + admin.phone + '\n' + ' ' + admin.email + '\n' + ' ' + admin.role + '\n' + ' ' + admin.date + '\n' + ' \n' + ' 已启用\n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ''; } admin_lis += li; } //设置列表数据 $("#admin_msg").html(admin_lis); }); } servlet中功能代码: //分页、模糊查询 public void pageQuery(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //接收参数 String currentPageStr = request.getParameter("currentPage"); //接收admin_name管理员名称 String admin_name = request.getParameter("admin_name"); //判断admin_name是否为null if (admin_name != null && !"null".equals(admin_name) && admin_name.length() >

0) {admin_name = new String (admin_name.getBytes ("iso-8859-1"), "utf-8");} else {admin_name = "";} int currentPage = 0; / / current page number, no parameters are passed. Default is 1 if (currentPageStr! = null & & currentPageStr.length () > 0) {currentPage = Integer.parseInt (currentPageStr). } else {currentPage = 1;} / / displays the number of entries per page, default is 5 int pageSize = 5; / / call service to query PageBean object PageBean pb = service.pageQuery (currentPage, pageSize, admin_name); / / serialize pageBean object to json and return writeValue (pb, response);}

Code implementation in the service layer:

@ Override public PageBean pageQuery (int currentPage, int pageSize, String admin_name) {/ / Encapsulation PageBean PageBean pb = new PageBean (); / / set the current page number pb.setCurrentPage (currentPage); / / set the number of entries displayed per page pb.setPageSize (pageSize); / / set the total number of records int totalCount = dao.findTotalCount (admin_name); pb.setTotalCount (totalCount) / / set the data set displayed on the current page int start = (currentPage-1) * pageSize; / / the number of records starting List list = dao.findByPage (start, pageSize, admin_name); pb.setList (list); / / set total number of pages = total number of records / number of entries displayed per page int totalPage = totalCount% pageSize = = 0? TotalCount / pageSize: (totalCount / pageSize) + 1; pb.setTotalPage (totalPage); return pb;}

Code implementation in the dao layer:

@ Override public int findTotalCount (String admin_name) {/ / define sql template String sql = "SELECT COUNT (*) FROM administrator WHERE 1cm 1"; StringBuilder sb = new StringBuilder (sql); / / conditional List params = new ArrayList (); if (admin_name! = null & & admin_name.length () > 0) {sb.append ("and aname like?") Params.add ("%" + admin_name + "%");} sql = sb.toString (); return template.queryForObject (sql, Integer.class, params.toArray ());} @ Override public List findByPage (int start, int pageSize, String admin_name) {String sql = "SELECT * FROM administrator WHERE 1x1"; StringBuilder sb = new StringBuilder (sql) / / condition List params = new ArrayList (); / / determine whether the parameter has a value if (admin_name! = null & & admin_name.length () > 0) {sb.append ("and aname like?"); params.add ("%" + admin_name + "%") } / / paging condition sb.append ("limit?,?"); params.add (start); params.add (pageSize); / / convert the string sql = sb.toString (); return template.query (sql, new BeanPropertyRowMapper (Administrator.class), params.toArray ());}

Achieve results:

User list

Design idea: it is basically similar to the administrator list design idea.

Achieve results:

Order management

Design idea: it is basically similar to the administrator list design idea.

These are all the contents of the article "how to develop a user background management system with Java". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report