仅供参考,不可转载,如遇其他情况概不负责,后果自负,切记
该项目运用的技术:spring+springMVC+ibatis
本网页只有一个页面,包过信息的增、删、改、查功能,只有部分代码,仅供参考
因该项目比较大,所以仅提供了一个页面内的增删改查,用到的数据表有用户表、角色表、用户角色表三张表来实现。
在这里面只有service、serviceImpl以及sql语句,没有前端的jsp与后端的Controller,可在java实现信息的增删改查功能的网页设计(1)里面查看。
后端service
public interface User1Service {
public abstract String getUsers1(User1Bean bean);
public abstract User1Model getUserById(String s);
public abstract String getUserRole1Str(String s);
public abstract boolean add(User1Model user1Model);
public abstract int delete(String s);
public abstract int update(User1Model user1model);
}
后端serviceImpl
@Service
public class User1ServiceImpl implements User1Service {
@Resource
private IBaseDao dao;
@Resource
private ExtFieldService fieldService;
//查询
@Override
public String getUsers1(User1Bean bean) {
bean.setUserIsAdmin(UserCenterService.getCurrentUserInfo().getUserIsAdmin());
Pager pager = dao.getPageList("com.hyjx.business.text.getusers", "com.hyjx.business.text.getusersNum", bean);
for(Iterator iterator = pager.getResultList().iterator(); iterator.hasNext();)
{
User1Model model = (User1Model)iterator.next();
String departCode = model.getDepart_code();
//System.out.println(departCode);
if(departCode != null && !"".equals(departCode))
{
DepartModel depart = RightManager.getDepartByCode(departCode);
if(depart != null)
model.setDepartName(depart.getDepart_name());
}
}
return dao.getJsonStrByPager(pager);
}
@Override
public User1Model getUserById(String s) {
User1Model model = null;
model = (User1Model) dao.queryObject("com.hyjx.business.text.getUserById", s);
return model;
}
@Override
public String getUserRole1Str(String id) {
List mk = null;
mk = dao.queryObjectList("com.hyjx.business.text.queryUserRole1List", id);
String iStr = "";
if (mk.size() > 0) {
for (Iterator iterator = mk.iterator(); iterator.hasNext();) {
UserRole1Model o = (UserRole1Model) iterator.next();
//StringBuilder:字符串拼接
iStr = (new StringBuilder(String.valueOf(iStr))).append(",").append(o.getRole_id()).toString();
}
return iStr.substring(1);
}else {
return iStr;
}
}
//添加
@Override
public boolean add(User1Model model) {
dao.addObject("com.hyjx.business.text.inserts", model);
saveRelation(model.getUser_id(),model.getRoleIds());
fieldService.update(model.getExtData());
return true;
}
private void saveRelation(String userId, String roleIds) {
if (roleIds != null && !"".equals(roleIds)) {
String id[] = roleIds.split(",");
List<UserRole1Model> list = new ArrayList<UserRole1Model>();
for (int i = 0; i < id.length; i++) {
String menuId = id[i];
if (menuId != null && !"".equals(menuId)) {
UserRole1Model rm = new UserRole1Model();
rm.setRole_id(menuId);
rm.setUser_id(userId);
rm.setId(StringHelper.getPrimaryKey());
list.add(rm);
}
} dao.batchInsertObject("com.hyjx.business.text.insertUserRole1", list);
}
}
//删除
@Override
public int delete(String id) {
dao.deleteObject("com.hyjx.business.text.deleteUserRole1", id);
return dao.deleteObject("com.hyjx.business.text.delete", id);
}
//修改
@Override
public int update(User1Model model) {
dao.deleteObject("com.hyjx.business.text.deleteUserRole1", model.getUser_id());
dao.updateObject("com.hyjx.business.text.update", model);
saveRelation(model.getUser_id(), model.getRoleIds());
fieldService.update(model.getExtData());
return 1;
}
}
ibatis语句
<?xml version="1.0" encoding="GBK" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="填入自己的ibatis路径">
<typeAlias alias="user1Model" type="填入自己model的路径"/>
<typeAlias alias="userrole1Model" type="填入自己用户角色表的model路径"/>
<!-- 查询所有对象 -->
<select id="getusers" parameterClass="填入自己bean的路径" resultClass="user1Model">
SELECT * from SYS_RIGHT_USER
where 1=1 and status = '1'
<isEqual property="includChild" compareValue="1">
and depart_code in (select depart_code from sys_right_depart where depart_code_full like '$departCode$.%' or depart_code_full like '%.$departCode$.%')
</isEqual>
<isEqual property="includChild" compareValue="0">
and depart_code = #departCode#
</isEqual>
<isNotEmpty property="userAccount">
and user_account like '%$userAccount$%'
</isNotEmpty>
<isNotEmpty property="userName">
and user_name like '%$userName$%'
</isNotEmpty>
order by validity desc,user_name
</select>
<select id="getusersNum" parameterClass="填入自己bean的路径" resultClass="java.lang.String">
SELECT count(user_id) from SYS_RIGHT_USER
where 1=1 and status='1'
<isEqual property="includChild" compareValue="1">
and depart_code in (select depart_code from sys_right_depart where depart_code_full like '$departCode$.%' or depart_code_full like '%.$departCode$.%')
</isEqual>
<isEqual property="includChild" compareValue="0">
and depart_code = #departCode#
</isEqual>
<isNotEmpty property="userAccount">
and user_account like '%$userAccount$%'
</isNotEmpty>
<isNotEmpty property="userName">
and user_name like '%$userName$%'
</isNotEmpty>
</select>
<select id="queryUserRole1List" parameterClass="java.lang.String" resultClass="userrole1Model">
select
ROLE_ID,
USER_ID
from
SYS_RIGHT_USER_ROLE
where 1=1
AND USER_ID=#id#
</select>
<select id="getUserById" parameterClass="java.lang.String" resultClass="user1Model">
select
*
from
SYS_RIGHT_USER
where 1=1
and user_id = #user_id#
</select>
<insert id="inserts" parameterClass="user1Model" >
insert into sys_right_user(user_id,org_code,depart_code,user_account,user_name,user_sex,
user_pwd,office_tel,office_fax,mobile,email,validity,create_time,update_time,picture_name,status)
values(#user_id#,#org_code#,#depart_code#,#user_account#,#user_name#,#user_sex#,
#user_pwd#,#office_tel#,#office_fax#,#mobile#,#email#,#validity#,#create_time#,#update_time#,#picture_name#,'1')
</insert>
<insert id="insertUserRole1" parameterClass="userrole1Model">
insert into SYS_RIGHT_USER_ROLE (
role_id,
user_id,id
)values(
#role_id#,
#user_id#,#id#
)
</insert>
<delete id="delete" parameterClass="java.lang.String">
delete from SYS_RIGHT_USER
where 1=1
and user_id = #user_id#
</delete>
<delete id="deleteUserRole1" parameterClass="java.lang.String">
delete from SYS_RIGHT_USER_ROLE
where 1=1
and USER_id = #id#
</delete>
<update id="update" parameterClass="user1Model" >
update sys_right_user set
depart_code = #depart_code#,
org_code = #org_code#,
user_account = #user_account#,
user_name = #user_name#,
user_sex = #user_sex#,
<isNotEmpty property="user_pwd">
<isNotNull property="user_pwd">
<isNotEqual property="user_pwd" compareValue="">
user_pwd = #user_pwd#,
</isNotEqual>
</isNotNull>
</isNotEmpty>
office_tel =#office_tel#,
office_fax = #office_fax#,
mobile = #mobile#,
email = #email#,
validity = #validity#,picture_name=#picture_name#,
update_time=#update_time#
where user_id = #user_id#
</update>
</sqlMap>
如遇到问题可在评论区评论或私信博主
不可转载,负责后果自负,其他情况概不负责,仅供参考