UserServiceImpl.java
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.tianbo.service.imp;
import com.tianbo.common.ModelAndPage;
import com.tianbo.mapper.UsersMapper;
import com.tianbo.model.Users;
import com.tianbo.model.UsersExample;
import com.tianbo.service.UserService;
import com.tianbo.util.dao.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
* Created by mrz on 2017/8/23.
*/
@Service
public class UserServiceImpl implements UserService{
@Autowired
private UsersMapper userMapper;
public List<Users> findUser() throws Exception{
//调用mapper类中的selectByExample方法,如果传入类型为null,则表示无条件查找
UsersExample example = new UsersExample();
example.setOrderByClause("username"); //设置order 字段
// example.or().andAddressLike("datong").andUsernameEqualTo("mrz");//搜索条件
List<Users> users = userMapper.selectByExample(example);
return users;
}
public void addUser(Users user){
userMapper.insert(user);
}
public Users selectByUserId(BigDecimal id){
Users user = userMapper.selectByPrimaryKey(id);
return user;
}
public ModelAndPage userList(Integer dataStart,Integer perPage,Users user)throws Exception{
//调用mapper类中的selectByExample方法,如果传入类型为null,则表示无条件查找
UsersExample example = new UsersExample();
UsersExample.Criteria criteria = example.createCriteria();
if (user.getMobilephone()!=null){
criteria.andMobilephoneEqualTo(user.getMobilephone());
}
if (user.getUsername()!=null){
criteria.andUsernameEqualTo(user.getUsername());
}
example.setOrderByClause("user_id"); //设置order 字段
int count = userMapper.countByExample(example); //没加入分页前的搜索总数据数
Page page = new Page(dataStart,perPage);
page.setCount(count);
example.setPage(page); //oracle 用这个
List<Users> users = userMapper.selectByExample(example);
ModelAndPage<Users> modelAndPage = new ModelAndPage(users,page);
return modelAndPage;
}
public int countByExample(UsersExample example){
return userMapper.countByExample(example);
}
public int updateByPrimaryKey(Users record){
return userMapper.updateByPrimaryKey(record);
}
public int insert(Users record){
return userMapper.insert(record);
}
public int deleteByPrimaryKey(BigDecimal userId){
return userMapper.deleteByPrimaryKey(userId);
}
/**
*
* @param user
* @return true代表有,FALSE代表无
*/
public boolean checkUser(Users user){
//调用mapper类中的selectByExample方法,如果传入类型为null,则表示无条件查找
UsersExample example = new UsersExample();
UsersExample.Criteria criteria = example.createCriteria();
if (user.getUsername()!=null){
criteria.andUsernameEqualTo(user.getUsername());
}
int count = userMapper.countByExample(example);
if (count>0){
return true;
}else {
return false;
}
}
}