Skip to content

Commit

Permalink
Merge pull request #1 from zhaojun1998/dev
Browse files Browse the repository at this point in the history
✨ 角色列表, 激活, 禁用功能.
  • Loading branch information
zhaojun1998 authored Oct 21, 2018
2 parents e17f3b4 + 733adb0 commit 742e895
Show file tree
Hide file tree
Showing 24 changed files with 341 additions and 311 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.9</version>
</dependency>
</dependencies>

<build>
Expand Down
42 changes: 35 additions & 7 deletions src/main/java/im/zhaojun/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
package im.zhaojun.controller;

import im.zhaojun.mapper.UserMapper;
import im.zhaojun.model.User;
import com.github.pagehelper.PageInfo;
import im.zhaojun.model.vo.UserVO;
import im.zhaojun.service.UserService;
import im.zhaojun.util.PageResultBean;
import im.zhaojun.util.ResultBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class UserController {

@Resource
private UserMapper userMapper;
private UserService userService;

@RequestMapping("/user")
@GetMapping("/users")
public String getUsers() {
return "member-list";
}

@GetMapping("/users/page")
@ResponseBody
public PageResultBean<UserVO> userList(@RequestParam(value = "username", required = false) String username,
@RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "limit", defaultValue = "10")int limit) {
List<UserVO> users = userService.findListByUserName(username, page, limit);
PageInfo<UserVO> userPageInfo = new PageInfo<>(users);
return new PageResultBean<>(userPageInfo.getTotal(), userPageInfo.getList());
}


@PostMapping("/user/disable")
@ResponseBody
public ResultBean<Boolean> disable(Integer id) {
return new ResultBean<>(userService.disableUserByID(id));
}

@PostMapping("/user/enable")
@ResponseBody
public User get() {
return userMapper.selectByPrimaryKey(1);
public ResultBean<Boolean> enable(Integer id) {
return new ResultBean<>(userService.enableUserByID(id));
}
}
5 changes: 5 additions & 0 deletions src/main/java/im/zhaojun/mapper/UserMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Set;

@Mapper
Expand All @@ -25,4 +26,8 @@ public interface UserMapper {
Set<String> findRoleNameByUserName(@Param("username")String username);

User findOneByUserName(@Param("username")String username);

List<User> findListByUserName(@Param("likeUsername")String likeUsername);

int updateStatusByPrimaryKey(@Param("id") Integer id, @Param("status") int status);
}
55 changes: 55 additions & 0 deletions src/main/java/im/zhaojun/model/vo/UserVO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package im.zhaojun.model.vo;

import java.util.Date;

public class UserVO {
private Integer userId;

private String username;

private String email;

private String status;

private Date lastLoginTime;

public Integer getUserId() {
return userId;
}

public void setUserId(Integer userId) {
this.userId = userId;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public Date getLastLoginTime() {
return lastLoginTime;
}

public void setLastLoginTime(Date lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}
}
40 changes: 40 additions & 0 deletions src/main/java/im/zhaojun/service/UserService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package im.zhaojun.service;

import com.github.pagehelper.PageHelper;
import im.zhaojun.mapper.UserMapper;
import im.zhaojun.model.User;
import im.zhaojun.model.vo.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserService {

@Resource
private UserMapper userMapper;

public List<UserVO> findListByUserName(String username, int page, int rows) {
PageHelper.startPage(page, rows);
List<User> userList = userMapper.findListByUserName(username);
List<UserVO> userVOList = new ArrayList<>();
for (User user : userList) {
UserVO userVO = new UserVO();
BeanUtils.copyProperties(user, userVO);
userVOList.add(userVO);
}
return userVOList;
}

public boolean disableUserByID(Integer id) {
return userMapper.updateStatusByPrimaryKey(id, 0) == 1;
}

public boolean enableUserByID(Integer id) {
return userMapper.updateStatusByPrimaryKey(id, 1) == 1;
}

}
15 changes: 15 additions & 0 deletions src/main/resources/mapper/UserMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,19 @@
from user
where username=#{username,jdbcType=VARCHAR} limit 1
</select>


<select id="findListByUserName" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from user
where 1=1
<if test="likeUsername!=null">
and username like CONCAT('%', #{likeUsername,jdbcType=VARCHAR}, '%')
</if>
</select>

<update id="updateStatusByPrimaryKey">
update user set status = #{status} where user_id = #{id}
</update>
</mapper>
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin-add.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="./lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin-cate.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="./lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin-edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="./lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="./lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin-role.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="./lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin-rule.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="./lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/cate.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="./lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/city.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="./lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
Expand Down
Loading

0 comments on commit 742e895

Please sign in to comment.