当前位置: 代码迷 >> 综合 >> 后台增删查改统一性代码
  详细解决方案

后台增删查改统一性代码

热度:19   发布时间:2024-02-26 14:48:48.0
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>

 

  相关解决方案