美文网首页
2023-12-27 后端角色搭建

2023-12-27 后端角色搭建

作者: 大也 | 来源:发表于2024-01-04 09:40 被阅读0次
image.png

大哥 他不会报错
他不会报错 你知道吗?
下次 写的时候先 放到 navicate运行
放到 最前面 这种 sb错误 真的不能有下次 他不会报错你知道吗 我哭了

完成后端搭建
注意点

  1. pagehelper的介入和使用 整合 之前学习的 内容 我会出个 pagehelper 模版类
    2.后面mypaticplus 也有用到这部分 而且返回会多层封装 内容会更不一样
    3.他这里 接口用的是 路径的 在客户端为了统一封装 基本都是 post 请求 这里也会不一样
    4.mapper。xml模版类更新 搜索。直接复制的例子
    可以直接看到 标签 一般sql resultMap 的使用
    5.resultMap 需要掌握多层嵌套 单层的之后用mypaticplus 整合的mybaitcX 和 单层映射配置开关 基本不用写sql

慢慢也要把 模版类分成 概念模版和快捷使用模版

1.controller
@RestController
@RequestMapping("/admin/system/sysRole")
public class SysRoleController {

private SysRoleService sysRoleService;

/**
 //1 角色列表的方法
 // current:当前页   limit:每页显示记录数
 // SysRoleDto: 条件角色名称对象
 */
@PostMapping("/findByPage/{curr}/{limit}")
public Result findByPage(@PathVariable("current") Integer curr,
                         @PathVariable("limit") Integer limit,
                         @RequestBody SysRoleDto sysRoleDto
                         ){
    PageInfo<SysRole> pageInfo = sysRoleService.findByPage( curr,
             limit,
             sysRoleDto);

    return Result.build(pageInfo,ResultCodeEnum.SUCCESS);
}

}
2.server
public interface SysRoleService {

PageInfo<SysRole> findByPage(Integer curr,
                             Integer limit,
                             SysRoleDto sysRoleDto);

}
2.2 server Impl
public class SysRoleServiceImpl implements SysRoleService {

@Autowired
private SysRoleMapper sysRoleMapper;
@Override
public PageInfo<SysRole> findByPage(Integer curr, Integer limit, SysRoleDto sysRoleDto) {
    /**
     //角色列表的方法
     //设置分页参数
     //根据条件查询所有数据
     //封装pageInfo对象
     * */

    PageHelper.startPage(curr,limit);
    List<SysRole> list = sysRoleMapper.findByPage(sysRoleDto);
    PageInfo<SysRole> pageInfo = new PageInfo<SysRole>(list);
    return pageInfo;
}

}

3.mapper
public interface SysRoleMapper {
List<SysRole> findByPage(SysRoleDto sysRoleDto);
}
3.2 mapper 。xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.atguigu.spzx.manager.mapper.SysRoleMapper">


<resultMap id="sysRoleMap" type="com.atguigu.spzx.model.entity.system.SysRole" autoMapping="true"></resultMap>
<sql id="columns">
id,role_name,role_code,description,create_time,update_time,is_deleted
</sql>

<select id="findByPage" resultMap="sysRoleMap">
    selected <include refid="columns"/>
    from sys_role
    <where>
        <if test="roleName != null and roleName != ''">
            and role_name like concat('%',#{roleName},'%')
        </if>
        and is_deleted=0
    </where>
    order by id desc
</select>

</mapper>

相关文章

网友评论

      本文标题:2023-12-27 后端角色搭建

      本文链接:https://www.haomeiwen.com/subject/ggmlndtx.html