後臺增刪查改統一性代碼

controller:
@PreAuthorize("@ss.hasPermi('system:role:list')")  //和數據庫中的menu中的字段有關係
@GetMapping("list")
public TableDataInfo list(SysRole role){
	startPage();
	List<SysRole> list = roleService.selectRoleList(role);
	return getDataInfo(list);
}

表格分頁數據對象
public class TableDataInfo implements Serializable{
	private static final long serialVersionUID = 1L;
	//總記錄數量
	private long total;
	//列表數據
	private List<?> rows;
	//消息狀態碼
	private int code;
	//消息內容
	private String msg;

	//表格數據對象 ==無參構造
	public TableDataInfo(){}

	//有參數構造,分頁,list列表數據,total總記錄數
	public TableDataInfo(List<?> list,int total){
		this.rows = list;
		this.total = total;
	}
	public long getTotal(){
		 return total;
	}
	public void setTotal(long total){
		this.total = total;
	}
	public List<?> getRows(){
		return rows;
	}
	public List<?> setRows(List<?> rows){
		this.rows = rows
	}
	public int getCode(){
		return code;
	}
	public void setCode(int code){
		this.code = code;
	}
	public String getMsg(){
		return msg;
	}
	public void setMsg(String msg){
		this.msg = msg;
	}

}

mapper.xml
<sql id="selectRoleVo">  連表查詢的sql語句,寫一遍就不用在單獨寫了 </sql>
列表展現和列表查詢展現角色信息的sql
<select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult">
	<include refid="selectRoleVo"/>
	where r.del_flag='0'
	<if test="roleName !=null and roleName!=''">
		and r.role_name like concat('%',#{roleName},'%')
	</if>
	<if test="beginTime !=null and beginTime !=''">
		and r.create_time &gt;= TO_DATE(#{beginTime},'YYYY-MM-DD HH24-MI-SS')
	</if>
</select>
統一性修改角色信息表的sql
<update id="updateRole" parameterType="SysRole">
	update sys_role
	<set>
		<if test="roleName!=null and roleName!=''">role_name=#{roleName},</if>
		<if test="status!=null and status!=''">status=#{status},</if>
		update_time= now()  或者是 current_timestamp
	</set>
	where role_id=#{roleId}
</update>
批量刪除角色信息的sql
<delete id="deleteRoleByIds" parameterType="String">
	update sys_role set del_flag = '2' where role_id  in 
	<foreach collection="array" item="roleId" open="(" separator="," close=")">
		#{roleId}
	</foreach>
</delete>
增長角色信息的統一性sql
<insert id="insertRole" parameterType="SysRole">
	insert into sys_role(
		<if test="roleId!=null and roleId!=''">role_id,</if>
		<if test="roleName!=null and roleName!=''">role_name,</if>
		create_time
	) values(
		<if test="roleId!=null and roleId!=''">#{roleId},</if>
		<if test="roleName!=null and roleName!=''">#{roleName},</if>
		current_timestamp
	)
</insert>
相關文章
相關標籤/搜索