Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 52d1535

Browse files
用户管理界面即用户列表获取
1 parent 5059c08 commit 52d1535

File tree

13 files changed

+940
-344
lines changed

13 files changed

+940
-344
lines changed

‎pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@
6767
<groupId>mysql</groupId>
6868
<artifactId>mysql-connector-java</artifactId>
6969
</dependency>
70-
70+
<dependency>
71+
<groupId>net.sourceforge.nekohtml</groupId>
72+
<artifactId>nekohtml</artifactId>
73+
<version>1.9.22</version>
74+
</dependency>
7175
</dependencies>
7276

7377
<build>

‎src/main/java/com/study/SpringbootShiroApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.study;
22

3+
import org.mybatis.spring.annotation.MapperScan;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56
import org.springframework.web.bind.annotation.RequestMapping;
67
import org.springframework.web.bind.annotation.RestController;
78

89
@RestController
910
@SpringBootApplication
11+
@MapperScan(basePackages = "com.study.mapper")
1012
public class SpringbootShiroApplication {
1113

1214
public static void main(String[] args) {

‎src/main/java/com/study/controller/HomeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public String login(){
1919

2020
@RequestMapping(value="/login",method=RequestMethod.POST)
2121
public String login(HttpServletRequest request, Map<String, Object> map){
22-
return "";
22+
return "user/users";
2323
}
2424

2525
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.study.controller;
2+
3+
import com.github.pagehelper.PageInfo;
4+
import com.study.model.User;
5+
import com.study.service.UserService;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RequestParam;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
import javax.annotation.Resource;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
/**
15+
* Created by yangqj on 2017年4月22日.
16+
*/
17+
@RestController
18+
@RequestMapping("/users")
19+
public class UserController {
20+
@Resource
21+
private UserService userService;
22+
23+
@RequestMapping
24+
public Map<String,Object> getAll(User user, String draw,
25+
@RequestParam(required = false, defaultValue = "1") int start,
26+
@RequestParam(required = false, defaultValue = "10") int length){
27+
Map<String,Object> map = new HashMap<>();
28+
PageInfo<User> pageInfo = userService.selectByPage(user, start, length);
29+
System.out.println("pageInfo.getTotal():"+pageInfo.getTotal());
30+
map.put("draw",draw);
31+
map.put("recordsTotal",pageInfo.getTotal());
32+
map.put("recordsFiltered",pageInfo.getTotal());
33+
map.put("data", pageInfo.getList());
34+
return map;
35+
}
36+
37+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.study.service;/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 abel533@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
import org.springframework.stereotype.Service;
26+
27+
import java.util.List;
28+
29+
/**
30+
* 通用接口
31+
*/
32+
@Service
33+
public interface IService<T> {
34+
35+
T selectByKey(Object key);
36+
37+
int save(T entity);
38+
39+
int delete(Object key);
40+
41+
int updateAll(T entity);
42+
43+
int updateNotNull(T entity);
44+
45+
List<T> selectByExample(Object example);
46+
47+
//TODO 其他...
48+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.study.service;
22

3+
import com.github.pagehelper.PageInfo;
4+
import com.study.model.User;
5+
36
/**
47
* Created by yangqj on 2017年4月21日.
58
*/
6-
public interface UserService {
9+
public interface UserService extends IService<User>{
10+
public PageInfo<User> selectByPage(User user, int start, int length);
711
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 abel533@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package com.study.service.impl;
26+
27+
import com.study.service.IService;
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import tk.mybatis.mapper.common.Mapper;
30+
31+
import java.util.List;
32+
33+
/**
34+
* Created by liuzh on 2014年12月11日.
35+
*/
36+
public abstract class BaseService<T> implements IService<T> {
37+
38+
@Autowired
39+
protected Mapper<T> mapper;
40+
41+
public Mapper<T> getMapper() {
42+
return mapper;
43+
}
44+
45+
@Override
46+
public T selectByKey(Object key) {
47+
return mapper.selectByPrimaryKey(key);
48+
}
49+
50+
public int save(T entity) {
51+
return mapper.insert(entity);
52+
}
53+
54+
public int delete(Object key) {
55+
return mapper.deleteByPrimaryKey(key);
56+
}
57+
58+
public int updateAll(T entity) {
59+
return mapper.updateByPrimaryKey(entity);
60+
}
61+
62+
public int updateNotNull(T entity) {
63+
return mapper.updateByPrimaryKeySelective(entity);
64+
}
65+
66+
public List<T> selectByExample(Object example) {
67+
return mapper.selectByExample(example);
68+
}
69+
70+
//TODO 其他...
71+
}
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
11
package com.study.service.impl;
22

3+
import com.github.pagehelper.PageHelper;
4+
import com.github.pagehelper.PageInfo;
5+
import com.study.model.User;
36
import com.study.service.UserService;
7+
import org.springframework.stereotype.Service;
8+
import tk.mybatis.mapper.entity.Example;
9+
import tk.mybatis.mapper.util.StringUtil;
10+
11+
import java.util.List;
412

513
/**
614
* Created by yangqj on 2017年4月21日.
715
*/
8-
public class UserServiceImpl implements UserService{
16+
@Service
17+
public class UserServiceImpl extends BaseService<User> implements UserService{
18+
19+
@Override
20+
public PageInfo<User> selectByPage(User user, int start, int length) {
21+
int page = start/length+1;
22+
Example example = new Example(User.class);
23+
Example.Criteria criteria = example.createCriteria();
24+
if (StringUtil.isNotEmpty(user.getUsername())) {
25+
criteria.andLike("username", "%" + user.getUsername() + "%");
26+
}
27+
if (user.getId() != null) {
28+
criteria.andEqualTo("id", user.getId());
29+
}
30+
if (user.getEnable() != null) {
31+
criteria.andEqualTo("enable", user.getEnable());
32+
}
33+
//分页查询
34+
PageHelper.startPage(page, length);
35+
List<User> userList = selectByExample(example);
36+
return new PageInfo<>(userList);
37+
}
938
}

‎src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ spring.datasource.maxActive=20
3030
#spring.thymeleaf.content-type=text/html
3131
# set to false for hot refresh
3232
spring.thymeleaf.cache=false
33+
spring.thymeleaf.mode=LEGACYHTML5
3334

3435
mybatis.type-aliases-package=com.study.model
3536
mybatis.mapper-locations=classpath:mapper/*.xml

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /