拉勾教育后台管理系统(SSM)
广告模块
广告模块功能分析
拉勾教育后台管理系统的 广告管理模块包含了以下功能:
- 广告位列表查询
- 添加&修改广告位
- 回显广告位名称
- 广告分页查询
- 图片上传接口
- 新建&修改广告接口
- 回显广告信息
- 广告状态上下线
广告管理模块表设计
表关系介绍
1.ER图
2.数据实体描述
2.1 广告位表
字段名称 | 字段类型 | 约束 | 字段描述 |
---|---|---|---|
id | int(11) | 主键 | 广告位id |
name | varchar(255) | 广告位名称 | |
spaceKey | varchar(255) | 广告位标识 | |
createTime | datetime | 创建时间 | |
updateTime | datetime | 最后更新时间 | |
isDel | int(2) | 状态 |
2.2 广告表
字段名称 | 字段类型 | 约束 | 字段描述 |
---|---|---|---|
id | int(11) | 主键 | 广告ID |
name | varchar(255) | 广告名称 | |
spaceId | int(11) | 广告位ID | |
keyword | varchar(255) | 关键字 | |
htmlContent | varchar(255) | 文本内容 | |
text | varchar(255) | 备注 | |
img | varchar(255) | 图片链接 | |
link | varchar(255) | 跳转地址 | |
startTime | datetime | 开始时间 | |
endTine | datetimedatetime | 结束时间 | |
createTime | datetime | 创建时间 | |
updateTime | datetime | 最后更新时间 | |
status | int(2) | 状态(上架/下架) | |
priority | int(4) | 优先级 |
广告位列表查询
需求:点击广告列表按钮进行广告列表展示
查看接口文档,进行编码
实体类:PromotionSpace
public class PromotionSpace {
private Integer id;
private String name;
private String spaceKey;
private Date createTime;
private Date updateTime;
private Integer isDel;
}
Dao层:PromotionSpaceMapper
public interface PromotionSpaceMapper {
/*
获取所有的广告位
*/
public List<PromotionSpace> findAllPromotionSpace();
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lagou.dao.PromotionSpaceMapper">
<select id="findAllPromotionSpace" resultType="com.lagou.domain.PromotionSpace">
select * from promotion_space
</select>
</mapper>
Service层:PromotionSpaceService
public interface PromotionSpaceService {
/*
获取所有的广告位
*/
public List<PromotionSpace> findAllPromotionSpace();
}
@Service
public class PromotionSpaceServiceImpl implements PromotionSpaceService {
@Autowired
private PromotionSpaceMapper promotionSpaceMapper;
@Override
public List<PromotionSpace> findAllPromotionSpace() {
List<PromotionSpace> allPromotionSpace =
promotionSpaceMapper.findAllPromotionSpace();
return allPromotionSpace;
}
}
Web层:PromotionSpaceController
@RestController
@RequestMapping("/PromotionSpace")
public class PromotionSpaceController {
@Autowired
private PromotionSpaceService promotionSpaceService;
/*
查询所有广告位列表
*/
@RequestMapping("/findAllPromotionSpace")
public ResponseResult findAllPromotionSpace(){
List<PromotionSpace> allPromotionSpace =
promotionSpaceService.findAllPromotionSpace();
ResponseResult responseResult =
new ResponseResult(true,200,"响应成功",allPromotionSpace);
return responseResult;
}
}
添加&修改广告位
添加:点击广告列表按钮进行广告列表展示
修改:页面回显基础上,点击提交按钮 真正进行数据修改
查看接口文档,进行编码
查看接口文档
Dao层:PromotionSpaceMapper
public interface PromotionSpaceMapper {
/*
添加广告位
*/
public void savePromotionSpace(PromotionSpace promotionSpace);
/**
* 修改广告位
* */
public void updatePromotionSpace(PromotionSpace promotionSpace);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lagou.dao.PromotionSpaceMapper">
<insert id="savePromotionSpace"
parameterType="com.lagou.domain.PromotionSpace">
insert into promotion_space values(null,#{name},#{spaceKey},
#{createTime},#{updateTime},#{isDel})
</insert>
<update id="updatePromotionSpace"
parameterType="com.lagou.domain.PromotionSpace">
UPDATE promotion_space SET NAME = #{name},updateTime = #{updateTime}
where id = #{id}
</update>
</mapper>
Service层:PromotionSpaceService
public interface PromotionSpaceService {
void savePromotionSpace(PromotionSpace promotionSpace);
void updatePromotionSpace(PromotionSpace promotionSpace);
}
@Service
public class PromotionSpaceServiceImpl implements PromotionSpaceService {
@Autowired
private PromotionSpaceMapper promotionSpaceMapper;
@Override
public void savePromotionSpace(PromotionSpace promotionSpace) {
// 封装PromotionSpace
UUID uuid = UUID.randomUUID();
promotionSpace.setSpaceKey(uuid.toString());
promotionSpace.setCreateTime(new Date());
promotionSpace.setUpdateTime(new Date());
promotionSpace.setIsDel(0);
promotionSpaceMapper.savePromotionSpace(promotionSpace);
}
@Override
public void updatePromotionSpace(ProamotionSpace promotionSpace) {
promotionSpace.setUpdateTime(new Date());
promotionSpaceMapper.updatePromotionSpace(promotionSpace);
}
}
Web层:PromotionSpaceController
@RestController
@RequestMapping("/PromotionSpace")
public class PromotionSpaceController {
@Autowired
private PromotionSpaceService promotionSpaceService;
/*
添加&修改广告位
*/
@RequestMapping("/saveOrUpdatePromotionSpace")
public ResponseResult savePromotionSpace(@RequestBody PromotionSpace promotionSpace){
try {
if(promotionSpace.getId() == null){
//新增
promotionSpaceService.savePromotionSpace(promotionSpace);
ResponseResult responseResult = new ResponseResult(true,200,"响应成功","");
return responseResult;
}else{
//修改
promotionSpaceService.updatePromotionSpace(promotionSpace);
ResponseResult responseResult = new ResponseResult(true,200,"响应成功","");
return responseResult;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
回显广告位名称
需求:点击编辑按钮,进行广告位信息回显
Dao层:PromotionSpaceMapper
public interface PromotionSpaceMapper {
/**
* 根据id 查询广告位信息
* */
PromotionSpace findPromotionSpaceById(int id);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lagou.dao.PromotionSpaceMapper">
<select id="findPromotionSpaceById" parameterType="int" resultType="com.lagou.domain.PromotionSpace">
SELECT id,NAME FROM promotion_space WHERE id = #{id};
</select>
</mapper>
Service层:PromotionSpaceService
public interface PromotionSpaceService {
PromotionSpace findPromotionSpaceById(int id);
}
@Service
public class PromotionSpaceServiceImpl implements PromotionSpaceService {
@Autowired
private PromotionSpaceMapper promotionSpaceMapper;
@Override
public PromotionSpace findPromotionSpaceById(int id) {
PromotionSpace promotionSpace = promotionSpaceMapper.findPromotionSpaceById(id);
return promotionSpace;
}
}
Web层:PromotionSpaceController
@RestController
@RequestMapping("/PromotionSpace")
public class PromotionSpaceController {
@Autowired
private PromotionSpaceService promotionSpaceService;
/**
* 根据id查询 广告位信息
* */
@RequestMapping("/findPromotionSpaceById")
public ResponseResult findPromotionSpaceById(@RequestParam int id){
PromotionSpace promotionSpace =
promotionSpaceService.findPromotionSpaceById(id);
ResponseResult result = new ResponseResult(true,200,"响应成功",promotionSpace);
return result;
}
}
广告分页查询
需求:点击广告列表,对广告信息进行分页列表展示
实体类:PromotionAd
public class PromotionAd {
// 标识
private Integer id;
// 广告名
private String name;
// 广告位id
private Integer spaceId;
// 精确搜索关键词
private String keyword;
// 静态广告的内容
private String htmlContent;
// 文字一
private String text;
// 链接一
private String link;
// 开始时间
private Date startTime;
// 结束时间
private Date endTime;
private Date createTime;
private Date updateTime;
private Integer status;
// 优先级
private Integer priority;
private String img;
//声明一方关系
private PromotionSpace promotionSpace;
getter/setter..
}
PromotionAdVo
public class PromotionAdVo {
private Integer currentPage = 1;
private Integer pageSize = 10;
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
}
Dao层:PromotionAdMapper
public interface PromotionAdMapper {
/*
分页获取所有的广告列表
*/
public List<PromotionAd> findAllPromotionAdByPage();
}
<mapper namespace="com.lagou.dao.PromotionAdMapper">
<resultMap id="ad_space" type="com.lagou.domain.PromotionAd">
<id property="id" column="id"></id>
<result property="name" column="name"/>
<result property="spaceId" column="spaceId"/>
<result property="keyword" column="keyword"/>
<result property="htmlContent" column="htmlContent"/>
<result property="text" column="text"/>
<result property="link" column="link"/>
<result property="startTime" column="startTime"/>
<result property="endTime" column="endTime"/>
<result property="createTime" column="createTime"/>
<result property="updateTime" column="updateTime"/>
<result property="status" column="status"/>
<result property="priority" column="priority"/>
<result property="img" column="img"/>
<association property="promotionSpace"
select="com.lagou.dao.PromotionSpaceMapper.findPromotionSpaceById"
column="spaceId"
javaType="com.lagou.domain.PromotionSpace"></association>
</resultMap>
<!--分页查询广告信息-->
<select id="findAllPromotionAdByPage" resultMap="ad_space">
select * from promotion_ad
</select>
</mapper>
applicationContext-dao.xml引入分页插件
<!--2.sqlSessionFactory-->
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="typeAliasesPackage" value="com.lagou.domain"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>helperDialect=mysql</value>
</property>
</bean>
</array>
</property>
<!--引入加载mybatis核心配置文件-->
<property name="configLocation" value="classpath:sqlMapConfig.xml">
</property>
</bean>
Service层:PromotionAdService
public interface PromotionAdService {
/*
分页获取所有的广告列表
*/
public PageInfo findAllAdByPage(PromotionAdVo adVo);
}
@Service
public class PromotionAdServiceImpl implements PromotionAdService {
@Autowired
private PromotionAdMapper adMapper;
@Override
public PageInfo findAllAdByPage(PromotionAdVo adVo) {
PageHelper.startPage(adVo.getCurrentPage(),adVo.getPageSize());
List<PromotionAd> allAd = adMapper.findAllAdByPage();
PageInfo<PromotionAd> adPageInfo = new PageInfo<>(allAd);
return adPageInfo;
}
}
Web层:PromotionAdController
@RestController
@RequestMapping("/PromotionAd")
public class PromotionAdController {
@Autowired
private PromotionAdService promotionAdService;
/*广告分页查询*/
@RequestMapping("/findAllPromotionAdByPage")
public ResponseResult findAllPromotionAdByPage(PromotionAdVo adVo) {
PageInfo<PromotionAd> allPromotionAdByPage = promotionAdService.findAllPromotionAdByPage(adVo);
ResponseResult responseResult = new ResponseResult(true, 200, "广告分页数据查询成功", allPromotionAdByPage);
return responseResult;
}
}
图片上传接口
需求:添加广告页面,点击上传按钮,需完成图片上传
Web层:PromotionAdController
@RestController
@RequestMapping("/PromotionSpace")
public class PromotionSpaceController {
@Autowired
private PromotionSpaceService promotionSpaceService;
/*
文件上传
*/
@RequestMapping("/PromotionAdUpload")
public ResponseResult fileupload(@RequestParam("file") MultipartFile file,
HttpServletRequest request) throws IOException {
try {
//1.判断文件是否为空
if (file.isEmpty()) {
throw new RuntimeException();
}
//2.获取项目部署路径
String realPath = request.getServletContext().getRealPath("/");
String webappsPath = realPath.substring(0, realPath.indexOf("ssm_web"));
//3.获取原文件名
String fileName = file.getOriginalFilename();
//4.新文件名
String newFileName = System.currentTimeMillis() +
fileName.substring(fileName.lastIndexOf("."));
//5.上传文件
String uploadPath = webappsPath + "upload\\";
File filePath = new File(uploadPath, newFileName);
//如果目录不存在就创建目录
if (!filePath.getParentFile().exists()) {
filePath.getParentFile().mkdirs();
System.out.println("创建目录: " + filePath);
}
file.transferTo(filePath);
//6.将文件名和文件路径返回
Map<String, String> map = new HashMap<>();
map.put("fileName", newFileName);
map.put("filePath", LOCAL_URL + "/upload/" + newFileName);
ResponseResult result = new ResponseResult(true, 200, "响应成功", map);
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
新建&修改广告
新建需求:点击提交按钮,将页面内容保存到数据库
修改需求:点击编辑按钮,由前端实现数据回显,在回显页面进行数据修改,将修改后值更新到数据库中
Dao层:PromotionAdMapper
public interface PromotionAdMapper {
void savePromotionAd(PromotionAd promotionAd);
void updatePromotionAd(PromotionAd promotionAd);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lagou.dao.PromotionAdMapper">
<!--添加广告-->
<insert id="savePromotionAd" parameterType="com.lagou.domain.PromotionAd" >
INSERT INTO promotion_ad VALUES(NULL,#{name},#{spaceId},#{keyword},#
{htmlContent},#{text},#{link},#{startTime},#{endTime},#{createTime},#
{updateTime},#{status},#{priority},#{img});
</insert>
<!--更新广告-->
<update id="updatePromotionAd" parameterType="com.lagou.domain.PromotionAd">
update promotion_ad
<trim prefix="SET" suffixOverrides=",">
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="spaceId != null and spaceId != ''">
spaceId = #{spaceId},
</if>
<if test="link != null">
link=#{link},
</if>
<if test="status != null and status != '' or status == 0">
status=#{status},
</if>
<if test="img != null">
img=#{img},
</if>
<if test="text != null">
text=#{text},
</if>
<if test="startTime != null">
startTime=#{startTime},
</if>
<if test="endTime != null">
endTime=#{endTime},
</if>
<if test="updateTime != null">
updateTime=#{updateTime},
</if>
</trim>
<where>
<if test="id != null and id != '' ">id = #{id}</if>
</where>
</update>
</mapper>
Service层:PromotionAdService
public interface PromotionAdService {
void savePromotionAd(PromotionAd promotionAd);
void updatePromotionAd(PromotionAd promotionAd);
}
@Service
public class PromotionAdServiceImpl implements PromotionAdService {
@Autowired
private PromotionAdMapper adMapper;
@Override
public void savePromotionAd(PromotionAd promotionAd) {
adMapper.savePromotionAd(promotionAd);
}
@Override
public void updatePromotionAd(PromotionAd promotionAd) {
adMapper.updatePromotionAd(promotionAd);
}
}
Web层:PromotionAdController
@RestController
@RequestMapping("/PromotionAd")
public class PromotionAdController {
@Autowired
private PromotionAdService adService;
/*
新增或更新广告位置
*/
@RequestMapping("/saveOrUpdatePromotionAd")
public ResponseResult saveOrUpdatePromotionAd(@RequestBody PromotionAd promotionAd) {
try {
if (promotionAd.getId() == null) {
Date date = new Date();
promotionAd.setCreateTime(date);
promotionAd.setUpdateTime(date);
adService.savePromotionAd(promotionAd);
ResponseResult result = new ResponseResult(true, 200, "响应成功", null);
return result;
} else {
Date date = new Date();
promotionAd.setUpdateTime(date);
adService.updatePromotionAd(promotionAd);
ResponseResult result = new ResponseResult(true, 200, "响应成功", null);
return result;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
回显广告信息
需求:点击编辑按钮,进行广告位名称回显
Dao层:PromotionAdMapper
public interface PromotionAdMapper {
/**
* 根据id查询广告信息
* */
PromotionAd findPromotionAdById(int id);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lagou.dao.PromotionAdMapper">
<!-- 根据id查询广告信息 -->
<select id="findPromotionAdById" parameterType="int"
resultType="com.lagou.domain.PromotionAd">
SELECT
id,
NAME,
spaceId,
startTime,
endTime,
STATUS,
img,
link,
TEXT
FROM promotion_ad WHERE id = #{id}
</select>
</mapper>
Service层:PromotionAdService
public interface PromotionAdService {
/*
回显广告信息
*/
PromotionAd findPromotionAdById(int id);
}
@Service
public class PromotionSpaceServiceImpl implements PromotionSpaceService {
@Autowired
private PromotionAdMapper adMapper;
@Override
public PromotionAd findPromotionAdById(int id) {
PromotionAd promotionAd = adMapper.findPromotionAdById(id);
return promotionAd;
}
}
Web层:PromotionAdController
@RestController
@RequestMapping("/PromotionAd")
public class PromotionAdController {
@Autowired
private PromotionAdService adService;
/**
* 根据id回显 广告数据
* */
@RequestMapping("/findPromotionAdById")
public ResponseResult findPromotionAdById(@RequestParam int id){
try {
PromotionAd promotionAd = adService.findPromotionAdById(id);
ResponseResult result = new ResponseResult(true,200,"响应成功",promotionAd);
return result;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
广告状态上下线
需求:点击按钮,实现状态的动态上下线
Dao层:PromotionSpaceMapper
public interface PromotionAdMapper {
void updatePromotionAdStatus(PromotionAd promotionAd);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lagou.dao.PromotionAdMapper">
<!--void updatePromotionAdStatus(PromotionAd promotionAd);-->
<select id="updatePromotionAdStatus" parameterType="com.lagou.domain.PromotionAd">
UPDATE promotion_ad SET STATUS = #{status} ,updatetime = #{updateTime}
WHERE id = #{id}
</select>
</mapper>
Service层:PromotionAdService
public interface PromotionSpaceService {
void updatePromotionAdStatus(int id, int status);
}
@Service
public class PromotionSpaceServiceImpl implements PromotionSpaceService {
@Autowired
private PromotionAdMapper adMapper;
@Override
public void updatePromotionAdStatus(int id, int status) {
PromotionAd promotionAd = new PromotionAd();
promotionAd.setId(id);
promotionAd.setStatus(status);
promotionAd.setUpdateTime(new Date());
adMapper.updatePromotionAdStatus(promotionAd);
}
}
Web层:PromotionAdController
@RestController
@RequestMapping("/PromotionAd")
public class PromotionAdController {
@Autowired
private PromotionAdService adService;
/*
广告位置上下线
*/
@RequestMapping("/updatePromotionAdStatus")
public ResponseResult updateCourseStatus(@RequestParam int id,
@RequestParam int status) {
try {
//执行修改操作
if (status == 1) {
adService.updatePromotionAdStatus(id, status);
} else {
adService.updatePromotionAdStatus(id, 0);
}
//保存修改后的状态,并返回
Map<String, Integer> map = new HashMap<>();
map.put("status", status);
ResponseResult result = new ResponseResult(true, 200, "响应成功", map);
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
用户模块
用户模块功能分析
用户管理模块实现以下功能:
- 登陆(权限模块)
- 权限控制(权限模块)
- 用户分页&条件查询
- 用户状态设置
- 分配角色(权限模块)
用户管理模块表设计
表关系介绍
1.ER图
用户分页&条件查询
需求:实现多条件(手机号、注册开始时间和结束时间)分页组合查询
实体类UserVo。
注意使用了DateTimeFormat注解,使得传给controller的日期参数(格式为yyyy-MM-dd)自动转换成Date类型对象。
public class UserVo {
private Integer currentPage;
private Integer pageSize;
private String username;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date startCreateTime;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date endCreateTime;
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Date getStartCreateTime() {
return startCreateTime;
}
public void setStartCreateTime(Date startCreateTime) {
this.startCreateTime = startCreateTime;
}
public Date getEndCreateTime() {
return endCreateTime;
}
public void setEndCreateTime(Date endCreateTime) {
this.endCreateTime = endCreateTime;
}
}
Dao层:UserMapper
public interface UserMapper {
/*
查询所有用户
*/
public List<User> findAllUserByPage(UserVo userVo);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lagou.dao.UserMapper">
<!--查询所有用户-->
<select id="findAllUserByPage" resultType="com.lagou.domain.User">
SELECT
id,
NAME,
portrait,
phone,
PASSWORD,
STATUS,
create_time
FROM USER
<where>
<if test="true">
and is_del != 1
</if>
<if test="username != null">
and name = #{username}
</if>
<if test="startCreateTime != null and endCreateTime != null">
and create_time BETWEEN #{startCreateTime} AND #{endCreateTime}
</if>
</where>
</select>
</mapper>
Service层:UserService
public interface UserService {
/*
查询所有用户
*/
public PageInfo findAllUserByPage(UserVo userVo);
}
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public PageInfo findAllUserByPage(UserVo userVo) {
// 使用pageHelper
PageHelper.startPage(userVo.getCurrentPage(),userVo.getPageSize());
List<User> allUser = userMapper.findAllUser(userVo);
PageInfo<User> pageInfo = new PageInfo<User>(allUser);
System.out.println("总条数:"+pageInfo.getTotal());
System.out.println("总页数:"+pageInfo.getPages());
System.out.println("当前页:"+pageInfo.getPageNum());
System.out.println("每页显示长度:"+pageInfo.getPageSize());
System.out.println("是否第一页:"+pageInfo.isIsFirstPage());
System.out.println("是否最后一页:"+pageInfo.isIsLastPage());
return pageInfo;
}
}
Web层:UserController
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/findAllUserByPage")
public ResponseResult findAllUserByPage(@RequestBody UserVo userVo){
PageInfo pageInfo = userService.findAllUserByPage(userVo);
ResponseResult responseResult = new ResponseResult(true,200,"响应成功",pageInfo);
List<User> list = pageInfo.getList();
System.out.println(list);
return responseResult;
}
}
用户状态设置
需求分析:点击禁用,实现用户的状态变更
用户状态:ENABLE能登录,DISABLE不能登录
Dao层:UserMapper
public interface UserMapper {
/**
* 修改用户状态
* */
public void updateUserStatus(@Param("id") int id,@Param("status") String status);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lagou.dao.UserMapper">
<!-- 修改用户状态 -->
<update id="updateUserStatus">
UPDATE USER SET STATUS = #{status} where id = #{id};
</update>
</mapper>
Service层:UserService
public interface UserService {
/*
* 修改用户状态
* */
public void updateUserStatus(int id, String status);
}
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public void updateUserStatus(int id, String status) {
userMapper.updateUserStatus(id,status);
}
}
Web层:UserController
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
/**
* 修改用户状态
* ENABLE能登录,DISABLE不能登录
* */
@RequestMapping("/updateUserStatus")
public ResponseResult updateUserStatus(@RequestParam int id ,
@RequestParam String status){
if("ENABLE".equalsIgnoreCase(status)){
status = "DISABLE";
}else{
status = "ENABLE";
}
userService.updateUserStatus(id,status);
ResponseResult responseResult = new ResponseResult(true,200,"响应成功",status);
return responseResult;
}
}