Jsp页面常用的显示方

@RequestMapping(value = "/add", method=RequestMethod.GET)
<span style="white-space:pre">	</span>public String add(ModelMap model) {
<span style="white-space:pre">		</span>List<Authority> auths = authorityService.selectAllAuthority();
<span style="white-space:pre">		</span>model.addAttribute("auths", auths);
<span style="white-space:pre">		</span>return "manage/role/add";
<span style="white-space:pre">	</span>}

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="../common/top.jsp" />
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.cmcc.check.model.Role"%>
<%@page import="com.cmcc.check.model.Authority"%>

<form action="<%=request.getContextPath()%>/manage/tab1/role/add.html" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">角色名称</td>
            <td><input type="text" name="name" maxlength="20"/></td>
        </tr>
        <tr>
            <td class="tableleft">状态</td>
            <td>
                <input type="radio" name="roleStatus" value="0" checked/>启用
                <input type="radio" name="roleStatus" value="1"/>禁用
            </td>
        </tr>
        <tr>
            <td class="tableleft">权限</td>
            <td>
                <ul>
                	<%
				    List<Authority> auths = (List<Authority>) request.getAttribute("auths");
                	Authority auth = null;
                	if (auths != null) {
                		for (int i=0; i<auths.size(); i++) {
                			auth = auths.get(i);
						    %>
		                	<li>
				                <label class="checkbox inline"><input type="checkbox" name="authIds" value="<%=auth.getAuthorityId()%>"><%=auth.getName()%></label>
			                </li>
			                <%
				    	}
					}
					%>
                </ul> 
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <button type="submit" class="btn btn-primary" type="button">保存</button>   
                <button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
		        <%
		        	String message = (String) request.getAttribute("message");
		        	if(message != null)
		        		out.write("<span style='color:red'>"+message+"</span>");
		        %>
            </td>
        </tr>
    </table>
</form>
<script>
$(function () {
	$(':checkbox[name="group[]"]').click(function () {
		$(':checkbox', $(this).closest('li')).prop('checked', this.checked);
	});
	$('#backid').click(function(){
		window.location.href="<%=request.getContextPath()%>/manage/tab1/role/index.html";
	});
});
</script>
<jsp:include page="../common/bottom.jsp" />
/**
	 * 添加提交
	 */
	@RequestMapping(value = "/add", method=RequestMethod.POST)
	public String addSubmit(Role role, Long[] authIds, HttpServletRequest req, ModelMap model){
		if(role == null || StringUtils.isBlank(role.getName())){
			model.addAttribute("message", "输入参数不全");
			return add(model);
		}
		Long userid = (Long)req.getSession().getAttribute("userid");
		//TODO 获取当前操作人
		role.setCreator(userid == null ? 0L : userid);
		roleService.saveRoleObj(role, authIds);
		return "redirect:/manage/tab1/role/index.html";
	}


更改用户角色的权限:

/**
	 * 编辑角色
	 */
	@RequestMapping(value="/modify", method=RequestMethod.GET)
	public String modify(Long roleId, ModelMap model){
		Role role = roleService.getRoleById(roleId);
		Set<Long> authIds = roleAuthorityService.getAuthsByRole(roleId);
		List<Authority> auths = authorityService.selectAllAuthority();
		model.addAttribute("role", role);
		model.addAttribute("authIds", authIds);
		model.addAttribute("auths", auths);
		return "manage/role/modify";
	}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="../common/top.jsp" />
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Set"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.cmcc.check.model.Role"%>
<%@page import="com.cmcc.check.model.Authority"%>
<%@page import="com.cmcc.check.model.RoleAuthorityKey"%>
<%
Role role = (Role)request.getAttribute("role");
%>
<form action="<%=request.getContextPath()%>/manage/tab1/role/update.html" method="post" class="definewidth m20">
	<input type="hidden" name="roleId" value="<%=role.getRoleId()%>"/>
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">角色名称</td>
            <td><input type="text" name="name" maxlength="20" value="<%=role.getName()%>"/></td>
        </tr>
        <tr>
            <td class="tableleft">状态</td>
            <td>
                <input type="radio" name="roleStatus" value="0" <%if(role.getRoleStatus() == 0){%> checked <%} %>/>启用
                <input type="radio" name="roleStatus" value="1" <%if(role.getRoleStatus() == 1){%> checked <%} %>/>禁用
            </td>
        </tr>
        <tr>
            <td class="tableleft">权限</td>
            <td>
                <ul>
                	<%
				    List<Authority> auths = (List<Authority>) request.getAttribute("auths");
                	Authority auth = null;
                	if (auths != null) {
                		Set<Long> authIds = (Set<Long>) request.getAttribute("authIds");
                		for (int i=0; i<auths.size(); i++) {
                			auth = auths.get(i);
				    %>
                	<li>
		                <label class="checkbox inline"><input type="checkbox" <%if(authIds.contains(auth.getAuthorityId())){ %> checked <%} %> name="authIds" value="<%=auth.getAuthorityId()%>"><%=auth.getName()%></label>
	                </li>
	                <%
				    	}
					}
					%>
                </ul> 
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <button type="submit" class="btn btn-primary" type="button">修改</button>   
                <button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
                <%
		        	String message = (String) request.getAttribute("message");
		        	if(message != null)
		        		out.write("<span style='color:red'>"+message+"</span>");
		        %>
            </td>
        </tr>
    </table>
</form>
<script>
$(function () {
	$(':checkbox[name="group[]"]').click(function () {
		$(':checkbox', $(this).closest('li')).prop('checked', this.checked);
	});
	$('#backid').click(function(){
		window.location.href="<%=request.getContextPath()%>/manage/tab1/role/index.html";
	});
});
</script>
<jsp:include page="../common/bottom.jsp" />
/**
	 * 修改保存角色
	 */
	@RequestMapping(value = "/update", method=RequestMethod.POST)
	public String update(Role role, Long[] authIds, HttpServletRequest req, ModelMap model){
		
		if(role == null || role.getRoleId() == null)
			return "redirect:/manage/tab1/role/index.html";
		
		if(StringUtils.isBlank(role.getName())){
			model.addAttribute("message", "输入参数不全");
			return modify(role.getRoleId(), model);
		}
		
		Long userid = (Long)req.getSession().getAttribute("userid");
		//TODO 获取当前操作人
		role.setUpdateUser(userid == null ? 0L : userid);
		Set<Long> oldAuthIds = roleAuthorityService.getAuthsByRole(role.getRoleId());
		roleService.updateRoleObj(role, authIds, oldAuthIds);
		return "redirect:/manage/tab1/role/index.html";
	}

批量插入数据到数据库:

 <!-- 批量插入 -->
  <insert id="insertBatch" parameterType="java.util.List">
  	insert into role_auth (role_id, auth_id) 
  	values
  	<foreach collection="list" item="item" index="index" separator=",">
  		(${item.roleId}, ${item.authId})
  	</foreach>
  </insert>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值