当前位置:网站首页>Madness. Smbms (supermarket order management system)
Madness. Smbms (supermarket order management system)
2022-07-25 22:47:00 【Xiaobai, who just learned programming (• ̥́ ˍ •̀ ू )】
SMBMS( Supermarket order management system )
Code :( It is suggested that static resources and sql Bring them here to use , Others write it for yourself to practice . Pay attention to modifying relevant configuration files .)
link :https://pan.baidu.com/s/12MmpF9msJVjLT1U77XYfRw
Extraction code :11fv

database :

How to build a project ?
Consider whether to use Maven? rely on , jar package .
1. Preparation for project construction
- Building a maven web project .
- To configure Tomcat.
- Test whether the project can run .
- Pom.xml Import what is needed in the project jar package .(jsp,Servlet,mysql drive ,jstl,standard…)
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- servlet rely on -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<!-- JSP rely on -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
</dependency>
<!-- Connect to database -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!-- JSTL The dependency of expressions -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<!-- standard Tag library -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.80</version>
</dependency>
</dependencies>
- Create project package structure .

Write entity class .(pojo)
ROM mapping : surface — Class mapping .Public class writing .
1、 Database configuration file :
driver = com.mysql.jdbc.Driver
url = jdbc:mysql://localhost:3306/smbms?useUnicode=true&characterEncoding=utf8&useSSL=true
username = root
password = newpass
2、 Write the public class of the database :
package com.kuang.dao;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;
// Public classes that operate databases .
public class BaseDao {
private static String driver;
private static String url;
private static String username;
private static String password;
// Static code block , Class is initialized when it is loaded .
static {
Properties properties = new Properties();
// Read the corresponding resources through the class loader .
InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
try {
properties.load(is);
} catch (IOException e) {
e.printStackTrace();
}
driver = properties.getProperty("driver");
url = properties.getProperty("url");
username = properties.getProperty("username");
password = properties.getProperty("password");
}
// Get a link to the database .
public static Connection getConnection(){
Connection connection = null;
try {
Class.forName(driver);
connection = DriverManager.getConnection(url,username,password);
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
// Write query tool classes .
public static ResultSet execute(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet,String sql,Object[] params) throws SQLException {
preparedStatement = connection.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
//setObject, Placeholders from 1 Start , But our array is from 0 At the beginning .
preparedStatement.setObject(i+1,params[i]);
}
resultSet = preparedStatement.executeQuery();
return resultSet;
}
// Write, add, delete and modify public methods .
public static int execute(Connection connection,PreparedStatement preparedStatement,String sql,Object[] params) throws SQLException {
preparedStatement = connection.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
//setObject, Placeholders from 1 Start , But our array is from 0 At the beginning .
preparedStatement.setObject(i+1,params[i]);
}
int updateRows = preparedStatement.executeUpdate();
return updateRows;
}
// Release resources .
public static boolean closeResourse(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet){
boolean flag = true;
if (resultSet != null){
try {
resultSet.close();
//GC Recycling
resultSet = null;
} catch (SQLException throwables) {
throwables.printStackTrace();
flag = false;
}
}
if (preparedStatement != null){
try {
preparedStatement.close();
//GC Recycling
preparedStatement = null;
} catch (SQLException throwables) {
throwables.printStackTrace();
flag = false;
}
}
if (connection != null){
try {
connection.close();
//GC Recycling
connection = null;
} catch (SQLException throwables) {
throwables.printStackTrace();
flag = false;
}
}
return false;
}
}
3、 Write a character encoding filter ( Don't forget to register filters )
package com.kuang.filter;
import javax.servlet.*;
import java.io.IOException;
public class CharacterEncodingFilter implements Filter {
// Don't miss the wrong package. .
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
servletRequest.setCharacterEncoding("utf-8");
servletResponse.setCharacterEncoding("utf-8");
servletResponse.setContentType("text/html");
filterChain.doFilter(servletRequest,servletResponse);
}
@Override
public void destroy() {
}
}
<!-- Character encoding filter -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>com.kuang.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- Import static resources (js,css,img,calendar)
2. Login function realization

- Write front page ( Take it directly jsp Come and use )
- Set the home page
<!-- Set up the welcome page -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
- To write dao Layer login user login interface
// adopt userCode and userPassword, Get the user to log in .
public User getLoginUser(Connection connection,String userCode,String userPassword) throws SQLException;
- To write dao Implementation class of layer interface
// adopt userCode and userPassword, Get the user to log in .
@Override
public User getLoginUser(Connection connection, String userCode,String userPassword) throws SQLException {
PreparedStatement pstm = null;
ResultSet rs = null;
User user = null;
if (connection!=null){
String sql = "select * from smbms_user where userCode = ? and userPassword = ?";
Object[] params = {
userCode,userPassword};
rs = BaseDao.execute(connection,pstm,rs,sql,params);
if (rs.next()){
user = new User();
user.setId(rs.getInt("id"));
user.setUserCode(rs.getString("userCode"));
user.setUserName(rs.getString("userName"));
user.setUserPassword(rs.getString("userPassword"));
user.setGender(rs.getInt("gender"));
user.setBirthday(rs.getDate("birthday"));
user.setPhone(rs.getString("phone"));
user.setAddress(rs.getString("address"));
user.setUserRole(rs.getInt("userRole"));
user.setCreatedBy(rs.getInt("createdBy"));
user.setCreationDate(rs.getTimestamp("creationDate"));
user.setModifyBy(rs.getInt("modifyBy"));
user.setModifyDate(rs.getTimestamp("modifyDate"));
}
BaseDao.closeResourse(null,pstm,rs);
}
return user;
}
- Business layer interface
// The user login .
public User login(String userCode,String userPassword);
- Business layer implementation classes
// The business layer calls dao layer , So we're going to introduce Dao layer .
private UserDao userDao;
public UserServiceImpl() {
// Parameterless constructors .
userDao = new UserDaoImpl();
}
// The user login
@Override
public User login(String userCode, String userPassword) {
Connection connection = null;
User user = null;
try {
connection = BaseDao.getConnection();
// Call the corresponding specific database operation through the business layer .
user = userDao.getLoginUser(connection, userCode,userPassword);
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally {
BaseDao.closeResourse(connection,null,null);
}
return user;
}
- To write Servlet
package com.kuang.servlet.user;
import com.kuang.pojo.User;
import com.kuang.service.user.UserServiceImpl;
import com.kuang.util.Constants;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//Servlet: Control layer , Call the business layer code .
public class LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("LoginServlet---start...");
// Get user name and password .
String userCode = req.getParameter("userCode");
String userPassword = req.getParameter("userPassword");
// Compare it to the password in the database , Call the business layer ;
UserServiceImpl userService = new UserServiceImpl();
User user = userService.login(userCode, userPassword);// The person who logged in has been found here .
if (user!=null){
// Find this person , You can log in .
// Put the user's information in Session in ;
req.getSession().setAttribute(Constants.USER_SESSION,user);
// Jump to home .
resp.sendRedirect("jsp/frame.jsp");
}else {
// Check no one , Unable to log in .
// Forward back to the login page , By the way, remind it , Wrong username or password .
req.setAttribute("error"," Wrong username or password !");
req.getRequestDispatcher("login.jsp").forward(req,resp);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
- register Servlet
<!--Servlet-->
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.kuang.servlet.user.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login.do</url-pattern>
</servlet-mapping>
- Test access , Ensure that the above functions can be successful
3. Login function optimization
Logout function :
Ideas : remove session, Return to login page .
package com.kuang.servlet.user;
import com.kuang.util.Constants;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class LogoutServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Remove the user's Constants.USER_SESSION
req.getSession().removeAttribute(Constants.USER_SESSION);
resp.sendRedirect(req.getContextPath()+"/login.jsp");// Return to landing page .
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
register xml:
<servlet>
<servlet-name>LogoutServlet</servlet-name>
<servlet-class>com.kuang.servlet.user.LogoutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LogoutServlet</servlet-name>
<url-pattern>/jsp/logout.do</url-pattern>
</servlet-mapping>
4. Login blocking optimization
So that users can not directly enter the successful login page .
Write a filter , And register .
package com.kuang.filter;
import com.kuang.pojo.User;
import com.kuang.util.Constants;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class SysFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain Chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)resp;
// filter : from Session Get users .
User user = (User)request.getSession().getAttribute(Constants.USER_SESSION);
if (user==null){
// Has been removed or logged off , Or login .
response.sendRedirect("/SMBMS/error.jsp");
}else{
Chain.doFilter(req,resp);
}
}
@Override
public void destroy() {
}
}
register xml
<!-- User login filter -->
<filter>
<filter-name>SysFilter</filter-name>
<filter-class>com.kuang.filter.SysFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SysFilter</filter-name>
<url-pattern>/jsp/*</url-pattern>
</filter-mapping>
test , Sign in , Cancellation , jurisdiction , Make sure that OK.
5. Password change
- Import front-end material
<li><a href="${pageContext.request.contextPath }/jsp/pwdmodify.jsp"> Password change </a></li>
- Write project , It is suggested to write from the bottom up

- UserDao Interface
// Change the current user password .
public int updatePwd(Connection connection,int id,String password)throws SQLException;
- UserDao Interface implementation class
// Change the current user password .
@Override
public int updatePwd(Connection connection, int id, String password) throws SQLException {
PreparedStatement pstm = null;
int execute = 0;
if (connection!=null){
String sql = "update smbms_user set userPassword = ? where id = ?";
Object params[] = {
password,id};
execute = BaseDao.execute(connection,pstm,sql,params);
BaseDao.closeResourse(null,pstm,null);
}
return execute;
}
- UserService layer
// According to the user id Change Password .
public boolean updatePwd(int id,String password)throws SQLException;
- UserService Implementation class
// According to the user id Change Password .
@Override
public boolean updatePwd(int id, String pwd) throws SQLException {
Connection connection = null;
boolean flag = false;
// Change Password .
try {
connection = BaseDao.getConnection();
if (userDao.updatePwd(connection,id,pwd)>0){
flag = true;
}
} catch (SQLException throwables) {
throwables.printStackTrace();
} finally {
BaseDao.closeResourse(connection,null,null);
}
return flag;
}
- servlet Remember to implement reuse , To extract the method !
// Realization Servlet Reuse
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method = req.getParameter("method");
if (method.equals("savepwd")){
this.updatePwd(req,resp);
}else if (method.equals("pwdmodify")){
this.pwdModify(req,resp);
}else if (method.equals("query")){
this.query(req,resp);
}else if (method.equals("add")){
this.add(req,resp);
}else if (method.equals("modifyexe")){
this.modify(req,resp);
}else if (method.equals("deluser")){
this.delUser(req,resp);
}else if (method.equals("ucexist")){
this.userCodeExist(req, resp);
}else if (method.equals("getrolelist")){
this.getRoleList(req, resp);
}else if (method.equals("view")){
this.getUserById(req,resp,"userview.jsp");
}else if (method.equals("modify")){
this.getUserById(req,resp,"usermodify.jsp");
}
}
// Change Password
public void updatePwd(HttpServletRequest req, HttpServletResponse resp){
// from Session Take it inside id;
Object o = req.getSession().getAttribute(Constants.USER_SESSION);
String newpassword = req.getParameter("newpassword");
boolean flag = false;
if (o!=null && !StringUtils.isNullOrEmpty(newpassword)){
UserServiceImpl userService = new UserServiceImpl();
try {
flag = userService.updatePwd(((User)o).getId(),newpassword);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
if (flag){
req.setAttribute("message"," Password changed successfully , Please exit , Log in with the new password !");
// Password changed successfully , Remove current Session.
req.getSession().removeAttribute(Constants.USER_SESSION);
}else {
req.setAttribute("message"," Password change failed .");
}
}else {
req.setAttribute("message"," There is a problem with the new password .");
}
try {
req.getRequestDispatcher("pwdmodify.jsp").forward(req,resp);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
register xml
<servlet>
<servlet-name>UserServlet</servlet-name>
<servlet-class>com.kuang.servlet.user.UserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserServlet</servlet-name>
<url-pattern>/jsp/user.do</url-pattern>
</servlet-mapping>
- test
6. Optimize password modification Ajax
- alibaba.com fastjson( Import )
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.80</version>
</dependency>
- Background code modification
// Verify old password ,session There is the user's password in .
public void pwdModify(HttpServletRequest req, HttpServletResponse resp){
// from Session Take it inside id;
Object o = req.getSession().getAttribute(Constants.USER_SESSION);
String oldpassword = req.getParameter("oldpassword");
// Omnipotent Map: Result set
Map<String, String> resultMap = new HashMap<String, String>();
if (o==null){
//Session It doesn't work ,session Out of date .
resultMap.put("result","sessionerror");
}else if (StringUtils.isNullOrEmpty(oldpassword)){
// The password entered is empty .
resultMap.put("result","error");
}else {
String userPassword = ((User)o).getUserPassword();//Session User's password in .
if (oldpassword.equals(userPassword)){
resultMap.put("result","true");
}else {
resultMap.put("result","false");
}
}
try {
resp.setContentType("application/json");
PrintWriter writer = resp.getWriter();
//JSONArray alibaba.com JSON Tool class , Transformation format .
/* resultMap = ["reslut","sessionerror","reslut","error"] Json Format = {key:value} */
writer.write(JSONArray.toJSONString(resultMap));
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
- test
7. User management implementation

- Import paging tool class ——PageSupport
- User list page import ——userlist.jsp
1、 Get the number of users
- UserDao
// Query the total number of users according to user name or role .
public int getUserCount(Connection connection,String username,int userRole) throws SQLException;
- UserDaoImpl
// Query the total number of users according to user name or role .( The hardest thing to understand sql)
@Override
public int getUserCount(Connection connection,String username,int userRole) throws SQLException {
PreparedStatement pstm = null;
ResultSet rs = null;
int count = 0;
if (connection!=null){
StringBuffer sql = new StringBuffer();
sql.append("select count(1) as count from smbms_user u,smbms_role r where u.userRole = r.id");
ArrayList<Object> list = new ArrayList<Object>();// Store our parameters .
if (!StringUtils.isNullOrEmpty(username)){
sql.append(" and u.userName = ?");
list.add("%"+username+"%");//index:0 Fuzzy query .
}
if (userRole>0){
sql.append(" and u.userRole = ?");
list.add(userRole);//index:1
}
// How to handle list Convert to array .
Object[] params = list.toArray();
System.out.println("getUserCount Of sql sentence :"+sql.toString());// Output the last complete sql sentence .
rs = BaseDao.execute(connection, pstm, rs, sql.toString(), params);
if (rs.next()){
count = rs.getInt("count");// Get the final parameters from the result set .
}
BaseDao.closeResourse(null,pstm,rs);
}
return count;
}
- UserService
// Number of query records .
public int getUserCount(String username,int userRole);
- UserServiceImpl
// Number of query records .
@Override
public int getUserCount(String username, int userRole) {
Connection connection = null;
int count = 0;
try {
connection = BaseDao.getConnection();
count = userDao.getUserCount(connection,username,userRole);
} catch (SQLException throwables) {
throwables.printStackTrace();
} finally {
BaseDao.closeResourse(connection,null,null);
}
return count;
}
2、 Get the list of users
- UserDao
// Query users by criteria .( Pagination )
public List<User> getUserList(Connection connection, String userName, int userRole, int currentPageNo, int pageSize) throws Exception;
- UserDaoImpl
// Query users by criteria .( Pagination )
@Override
public List<User> getUserList(Connection connection, String userName, int userRole, int currentPageNo, int pageSize) throws Exception {
PreparedStatement pstm = null;
ResultSet rs = null;
List<User> userList = new ArrayList<User>();
if (connection != null) {
StringBuffer sql = new StringBuffer();
sql.append("select u.*,r.roleName as userRoleName from smbms_user u,smbms_role r where u.userRole = r.id");
List<Object> list = new ArrayList<Object>();
if (!StringUtils.isNullOrEmpty(userName)) {
sql.append(" and u.userName like ?");
list.add("%" + userName + "%");
}
if (userRole > 0) {
sql.append(" and u.userRole = ?");
list.add(userRole);
}
// stay mysql In the database , Paging using limit startIndex,pageSize ; total
sql.append(" order by creationDate DESC limit ?,?");
currentPageNo = (currentPageNo - 1) * pageSize;
list.add(currentPageNo);
list.add(pageSize);
Object[] params = list.toArray();
System.out.println("getUserList Of sql sentence :" + sql.toString());
rs = BaseDao.execute(connection, pstm, rs, sql.toString(), params);
while (rs.next()) {
User _user = new User();
_user.setId(rs.getInt("id"));
_user.setUserCode(rs.getString("userCode"));
_user.setUserName(rs.getString("userName"));
_user.setGender(rs.getInt("gender"));
_user.setBirthday(rs.getDate("birthday"));
_user.setPhone(rs.getString("phone"));
_user.setUserRole(rs.getInt("userRole"));
_user.setUserRoleName(rs.getString("userRoleName"));
userList.add(_user);
}
BaseDao.closeResourse(null, pstm, rs);
}
return userList;
}
- UserService
// Query the user list according to the criteria .
public List<User> getUserList(String queryUserName, int queryUserRole, int currentPageNo, int pageSize);
- UserServiceImpl
// Query the user list according to the criteria
@Override
public List<User> getUserList(String queryUserName, int queryUserRole, int currentPageNo, int pageSize) {
Connection connection = null;
List<User> userList = null;
try {
connection = BaseDao.getConnection();
userList = userDao.getUserList(connection, queryUserName, queryUserRole, currentPageNo, pageSize);
} catch (Exception e) {
e.printStackTrace();
} finally {
BaseDao.closeResourse(connection, null, null);
}
return userList;
}
3、 Get role operation
For the unity of our duties , We can put the operation of the role in a separate package , and pojo class .
- RoleDao
public interface RoleDao {
// Get a list of roles .
public List<Role> getRoleList(Connection connection)throws SQLException;
}
- RoleDaoIpml
public class RoleDaoImpl implements RoleDao{
// Get a list of roles .
@Override
public List<Role> getRoleList(Connection connection) throws SQLException {
PreparedStatement pstm = null;
ResultSet resultSet = null;
ArrayList<Role> rolelist = new ArrayList<>();
if (connection!=null){
String sql = "select * from smbms_role";
Object[] params = {
};
resultSet = BaseDao.execute(connection, pstm, resultSet, sql, params);
while (resultSet.next()){
Role role = new Role();
role.setId(resultSet.getInt("id"));
role.setRoleCode(resultSet.getString("roleCode"));
role.setRoleName(resultSet.getString("roleName"));
rolelist.add(role);
}
BaseDao.closeResourse(null,pstm,resultSet);
}
return rolelist;
}
}
- RoleService
public interface RoleService {
// Get a list of roles .
public List<Role> getRoleList();
}
- RoleServiceIpml
public class RoleServiceImpl implements RoleService{
// introduce Dao.
private RoleDao roleDao;
public RoleServiceImpl() {
roleDao = new RoleDaoImpl();
}
// Get a list of roles .
@Override
public List<Role> getRoleList() {
Connection connection = null;
List<Role> roleList = null;
try {
connection = BaseDao.getConnection();
roleList = roleDao.getRoleList(connection);
} catch (SQLException throwables) {
throwables.printStackTrace();
} finally {
BaseDao.closeResourse(connection,null,null);
}
return roleList;
}
}
4、 The user displays Servlet
- Get the user's front-end data ( Inquire about ).
- Determine whether the request needs to be executed , Judge by the value of the parameter .
- To achieve paging , You need to calculate the current page and the total page , Page size .
- User list display .
- Back to front .
// Query user list ( a key , difficulty ).
public void query(HttpServletRequest req, HttpServletResponse resp){
// Get data from the front end :
String queryUserName = req.getParameter("queryname");
String temp = req.getParameter("queryUserRole");
String pageIndex = req.getParameter("pageIndex");// The default is 1.
int queryUserRole = 0;
// Get the list of users
UserServiceImpl userService = new UserServiceImpl();
List<User> userList = null;
// For the first time, this request , It must be the first page , Fixed page size :
int pageSize = 5;// You can configure this into the configuration file , Convenient for later modification ;
int currentPageNo = 1;
if (queryUserName==null){
queryUserName = "";
}
if (temp!=null && !temp.equals("")){
queryUserRole = Integer.parseInt(temp); // Assign a value to the query !0,1,2,3
}
if (pageIndex!=null){
currentPageNo = Integer.parseInt(pageIndex);
}
// Get the total number of users ( Pagination : The previous page , On the next page )
int totalCount = userService.getUserCount(queryUserName,queryUserRole);
// The total number of pages supports .
PageSupport pageSupport = new PageSupport();
pageSupport.setCurrentPageNo(currentPageNo);
pageSupport.setPageSize(pageSize);
pageSupport.setTotalCount(totalCount);
int totalPageCount = pageSupport.getTotalPageCount();// There are several pages .
// Control the first and last pages .
// If the page is smaller than 1, Just show the first page .
if (currentPageNo<1){
currentPageNo = 1;
}else if (currentPageNo>totalPageCount){
// The current page is larger than the last page .
currentPageNo = totalPageCount;
}
// Get user list display .
userList = userService.getUserList(queryUserName, queryUserRole, currentPageNo, pageSize);
req.setAttribute("userList",userList);
RoleServiceImpl roleService = new RoleServiceImpl();
List<Role> roleList = roleService.getRoleList();
req.setAttribute("roleList",roleList);
req.setAttribute("totalCount",totalCount);
req.setAttribute("currentPageNo",currentPageNo);
req.setAttribute("totalPageCount",totalPageCount);
req.setAttribute("queryUserName",queryUserName);
req.setAttribute("queryUserRole",queryUserRole);
// Back to front
try {
req.getRequestDispatcher("userlist.jsp").forward(req,resp);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Suggest : Little yellow duck debugging method : Think aloud .
Schematic flow chart of the project :

The code of the remaining two modules is directly CV Come and change it bug Add it ( Too lazy to write. !)
边栏推荐
- 【MySQL提权】UDF提权(附带大马)
- Common software shortcuts
- Recyclerview computehorizontalscrollextend computehorizontalscrollrange computehorizontalscroll for calculating the sliding distance
- 1000个Okaleido Tiger首发上线Binance NFT,引发抢购热潮
- CMU AI PhD first year summary
- XSS tool beef XSS installation and use
- [training Day11] Nescafe [greed]
- 【集训DAY13】Backpack【动态规划】【贪心】
- Qt中文编程遇C2001错误,提示“常量中有换行符”
- QT Chinese programming encounters c2001 error, prompting "there is a newline character in the constant"
猜你喜欢

C语言逆序打印字符串的两种方法
![[training day15] boring [tree DP]](/img/78/dc80076bb9fc4cf008c51b00ece431.png)
[training day15] boring [tree DP]

【集训DAY11】Nescafe【贪心】

invalid syntax

Recyclerview computehorizontalscrollextend computehorizontalscrollrange computehorizontalscroll for calculating the sliding distance

【集训DAY13】Backpack【动态规划】【贪心】

Use of qvariant

IFLYTEK smart office book air e-book reader makes my work life healthier
![[training Day12] x equation [high precision] [mathematics]](/img/4f/51d902e925f9ec60da46d161ed4d17.png)
[training Day12] x equation [high precision] [mathematics]

Build commercial projects based on ruoyi framework
随机推荐
torchvision
Tfrecord write and read
Dom and events
IFLYTEK smart office book air e-book reader makes my work life healthier
Matrixcube unveils the complete distributed storage system matrixkv implemented in 102-300 lines
[training Day12] tree! Tree! Tree! [greed] [minimum spanning tree]
Build commercial projects based on ruoyi framework
Pyspark data analysis basis: pyspark.sql.sparksession class method explanation and operation + code display
Kibana~后台启动Kibana之后无法找到进程号
We media people must have four material websites, and don't worry about finding materials anymore
Domain oriented model programming
英文术语对应的解释
Floating effect and characteristics
Anaconda~Upload did not complete.
To light up all the positions in the string that need to be lit, at least a few lights are needed
ORM common requirements
【集训DAY12】X equation 【高精度】【数学】
The new media operation strategy (taking xiaohongshu as an example) helps you quickly master the creative method of popular models
Recyclerview computehorizontalscrollextend computehorizontalscrollrange computehorizontalscroll for calculating the sliding distance
自媒体人必备的4个素材网站,再也不用担心找不到素材