User management. Example tutorial of homepage query function
Page effect:
1. Click User Management

2. Enter the query conditions, query the database, and the data is echoed

Database implementation
#用户表CREATE TABLE Elec_User( UserID VARCHAR(50) NOT NULL, #主键ID JctID VARCHAR(50) NULL, #所属单位code JctUnitID VARCHAR(50) NULL, #所属单位的单位名称(联动) UserName VARCHAR(50) NULL, #用户姓名 LogonName VARCHAR(50) NULL, #登录名 LogonPwd VARCHAR(50) NULL, #密码# SexID VARCHAR(10) NULL, #性别 Birthday DATETIME NULL, #出生日期 Address VARCHAR(100) NULL, #联系地址 ContactTel VARCHAR(50) NULL, #联系电话 Email VARCHAR(50) NULL, #电子邮箱 Mobile VARCHAR(50) NULL, #手机 IsDuty VARCHAR(10) NULL, #是否在职 PostID VARCHAR(10) NULL, #职位(主要用于工作流审核) OnDutyDate DATETIME NULL, #入职时间 OffDutyDate DATETIME NULL, #离职时间 remark VARCHAR(500) NULL #备注 #IsDelete VARCHAR(10) NULL, #是否删除 #CreateEmpID VARCHAR(50) NULL,#创建人ID #CreateDate DATETIME NULL, #创建时间 #LastEmpID VARCHAR(50) NULL, #修改人ID #LastDate DATETIME NULL #修改时间 ) #用户职称附件表CREATE TABLE Elec_User_File( FileID VARCHAR(50) not null primary key, #主键ID UserID VARCHAR(50) NULL, #用户ID FileName VARCHAR(50) NULL, #文件名 FileURL VARCHAR(1000) NULL, #文件路径 ProgressTime TIMESTAMP NULL, #上传时间CONSTRAINT FOREIGN KEY(userID) REFERENCES Elec_User(userID) )domain designCreate 2 JavaBeans
Create the corresponding javabean file based on the user table and attachment table: ElecUser .java and ElecUserFile.java, the code is abbreviated
Create 2 xmlBecause one user corresponds to multiple attachments, the user table and attachment table are one-to-many relation.
1.ElecUser.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>nbsp;hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping><class><id><generator></generator></id><property></property><property></property><property></property><property> </property><property></property><property></property><property></property><property></property><property></property><property> </property><property></property><property></property><property></property><property></property><property></property><property> </property><!-- 一个用户对应多个文件 --><set><key><column></column></key><one-to-many></one-to-many></set> </class></hibernate-mapping>
2.ElecUserFile.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>nbsp;hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping><class><id><generator></generator></id><property></property><property></property><property></property><!-- 用户文件和用户是多对一的关系 --> <many-to-one> <column></column></many-to-one></class></hibernate-mapping>3
.Add in hibernate.cfg.xml:
<mapping></mapping><mapping></mapping>Dao DesignCreate Dao interface
1. User table Dao:ElecUserDao.java
##public interface IElecUserDao extends ICommonDao<elecuser> {public static final String SERVICE_NAME="cn.elec.dao.imp.ElecUserDaoImpl";
}</elecuser>

2. Attachment table Dao:ElecUserFileDao.java

public interface IElecUserFileDao extends ICommonDao<elecuserfile> {public static final String SERVICE_NAME="cn.elec.dao.imp.ElecUserFileDaoImpl";
}</elecuserfile>

1.ElecUserDaoImpl.java

@Repository(IElecUserDao.SERVICE_NAME)public class ElecUserDaoImpl extends ICommonDaoImpl<elecuser> implements IElecUserDao{
}</elecuser>

@Repository(IElecUserFileDao.SERVICE_NAME)public class ElecUserFileDaoImpl extends ICommonDaoImpl<elecuserfile>
implements IElecUserFileDao{
}</elecuserfile>

View Code
Service Design
public interface IElecUserService {public static final String SERVICE_NAME="cn.elec.service.impl.ElecUserServiceImpl";
List<elecuser> findUserlistByCondition(ElecUser elecUser);
}</elecuser>

View Code
Create Service implementation class
@Service(IElecUserService.SERVICE_NAME)
@Transactional(readOnly=true)public class ElecUserServiceImpl implements IElecUserService{//用户表Dao@Resource(name=IElecUserDao.SERVICE_NAME)private IElecUserDao elecUserDao;//附件表Dao@Resource(name=IElecUserFileDao.SERVICE_NAME)private IElecUserFileDao elecUserFileDao;//数据字典Dao@Resource(name=IElecSystemDDLDao.SERVICE_NAME)private IElecSystemDDLDao elecSystemDDLDao;/**
* @Name: findUserlistByCondition
* @Description: 根据查询条件返回查询结果
* @Parameters: ElecUser VO对象
* @Return: List<elecuser>:用户集合*/@Overridepublic List<elecuser> findUserlistByCondition(ElecUser elecUser) {
String condition="";
List<object> paramsList = new ArrayList<object>();//用户名String userName = elecUser.getUserName();if(StringUtils.isNotBlank(userName)){
condition+=" and o.userName like ?";
paramsList.add("%"+userName+"%");
}//所属单位String jctID = elecUser.getJctID();if(StringUtils.isNotBlank(jctID)){
condition+=" and o.jctID = ?";
paramsList.add(jctID);
}//查询的起始日期Date onDutyDateBegin = elecUser.getOnDutyDateBegin();if(onDutyDateBegin!=null){
condition+=" and o.onDutyDate >= ?";
paramsList.add(onDutyDateBegin);
}//查询的结束日期Date onDutyDateEnd = elecUser.getOnDutyDateEnd();if(onDutyDateBegin!=null){
condition+=" and o.onDutyDate orderby = new LinkedHashMap<string>();
orderby.put("o.onDutyDate", "asc");
List<elecuser> list = elecUserDao.findCollectionByConditionNoPage(condition, params, orderby);/**数据字典的转换
* 根据数据类型和数据编号,查询数据项的值 */this.convertSystemDDL(list);return list;
} //根据数据类型和数据编号,查询数据项的值private void convertSystemDDL(List<elecuser> list) {if(list!=null&&list.size()>0){for(ElecUser user:list){//性别String sexID=elecSystemDDLDao.findDdlNameByKeywordAndDdlCode("性别",user.getSexID());
user.setSexID(sexID);//职位String postID=elecSystemDDLDao.findDdlNameByKeywordAndDdlCode("职位",user.getPostID());
user.setPostID(postID);
}
}
}
}</elecuser></elecuser></string></object></object></elecuser></elecuser>
Action design
1.Create the UserAction class
public class ElecUserAction extends BaseAction<elecuser>{
ElecUser elecUser=this.getModel();
//注入用户管理service@Resource(name=IElecUserService.SERVICE_NAME)
IElecUserService elecUserService; //注入数据字典service@Resource(name=IElecSystemDDLService.SERVICE_NAME)
IElecSystemDDLService elecSystemDDLService; /**
* @Name: home
* @Description: 跳转到用户管理页面
* @Parameters: 无
* @Return: String:跳转到system/userIndex.jsp*/public String home(){//加载数据类型是所属单位的数据字典的集合,遍历在页面的下拉菜单中List<elecsystemddl> jctList = elecSystemDDLService.findSystemDDLListByKeyword("所属单位");
request.setAttribute("jctList", jctList);//组织页面中的查询条件,查询用户表,返回List<elecuser>List<elecuser> userList=elecUserService.findUserlistByCondition(elecUser);
request.setAttribute("userList", userList);return "home";
}
}</elecuser></elecuser></elecsystemddl></elecuser>
<!-- 用户管理 --><action>
<result>/WEB-INF/page/system/userIndex.jsp</result>
</action>
to struts.xml
Jsp页面设计


<script>
function deleteAll(){ var selectuser = document.getElementsByName("userID"); var flag = false; for(var i=0;i<selectuser.length;i++){ if(selectuser[i].checked){
flag = true;
}
} if(!flag){
alert("没有选择执行操作的用户!不能执行该操作"); return false;
} else{ var confirmflag = window.confirm("你确定执行批量删除吗?"); if(!confirmflag){ return false;
} else{
document.Form2.action = "elecUserAction_delete.do";
document.Form2.submit(); return true;
}
}
} //用户:全部选中/全部不选中
function checkAllUser(user){ var selectuser = document.getElementsByName("userID"); for(var i=0;i<selectuser.length;i++){
selectuser[i].checked = user.checked;
}
} </script>
<title>用户管理</title>
<link>
<script></script>
<script></script>
The above is the detailed content of User management. Example tutorial of homepage query function. For more information, please follow other related articles on the PHP Chinese website!
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PMThe article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.
How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PMThe article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.
How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PMThe article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra
How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PMThe article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]
How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PMJava's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.







