java实现信息的增删改查功能的网页设计(2)

仅供参考,不可转载,如遇其他情况概不负责,后果自负,切记

该项目运用的技术: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>

如遇到问题可在评论区评论或私信博主
不可转载,负责后果自负,其他情况概不负责,仅供参考

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

I心暖存人T

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值