Search in sources :

Example 1 with UserExample

use of com.hfut.entity.UserExample in project Workload by amoxu.

the class UserServiceImplTest method findByName.

@Test
public void findByName() {
    UserExample example = new UserExample();
    UserExample.Criteria criteria = example.createCriteria();
    criteria.andIdEqualTo(10000);
    List<User> userList = userMapper.selectByExample(example);
    Assert.assertEquals(userList.get(0).getUserRole().getName(), "超级管理员");
}
Also used : User(com.hfut.entity.User) UserExample(com.hfut.entity.UserExample) Test(org.junit.Test)

Example 2 with UserExample

use of com.hfut.entity.UserExample in project Workload by amoxu.

the class UserServiceImpl method register.

@Override
public boolean register(User user) throws Exception {
    System.out.println("user register:" + user.getUser() + " " + user.getPassword() + " " + user.getMail());
    if (StringUtils.isEmpty(user.getUser()) || StringUtils.isEmpty(user.getPassword())) {
        throw new CustomException("用户或密码不能为空!");
    } else if (StringUtils.isEmpty(user.getMail())) {
        throw new CustomException("邮箱不能为空!");
    } else if (user.getPassword().length() < 6) {
        throw new CustomException("密码过短!");
    }
    UserExample userExample = new UserExample();
    UserExample.Criteria criteria = userExample.createCriteria();
    criteria.andUserEqualTo(user.getUser());
    List<User> list = userMapper.selectByExample(userExample);
    if (list.size() != 0) {
        throw new CustomException("账号已存在!");
    }
    userExample = new UserExample();
    criteria = userExample.createCriteria();
    criteria.andMailEqualTo(user.getMail());
    list = userMapper.selectByExample(userExample);
    if (list.size() != 0) {
        throw new CustomException("邮箱已存在!");
    }
    int ret = userMapper.insert(user);
    if (ret > 0) {
        return true;
    } else {
        return false;
    }
}
Also used : User(com.hfut.entity.User) CustomException(com.hfut.exception.CustomException) UserExample(com.hfut.entity.UserExample)

Example 3 with UserExample

use of com.hfut.entity.UserExample in project Workload by amoxu.

the class UserServiceImpl method findByName.

/*   private SimpleMailMessage mailMessage;
    private JavaMailSender mailSender;*/
@Override
public User findByName(String name) throws Exception {
    UserExample userExample = new UserExample();
    UserExample.Criteria criteria = userExample.createCriteria();
    criteria.andUserEqualTo(name);
    List<User> list = userMapper.selectByExample(userExample);
    if (list.size() == 0) {
        return null;
    } else {
        return list.get(0);
    }
}
Also used : User(com.hfut.entity.User) UserExample(com.hfut.entity.UserExample)

Example 4 with UserExample

use of com.hfut.entity.UserExample in project Workload by amoxu.

the class UserServiceImpl method getList.

@Override
public List<User> getList(Integer page, Integer limit) throws Exception {
    UserExample example = new UserExample();
    example.setLimit(limit);
    if (page != 0) {
        page -= 1;
    }
    example.setOffset(page);
    List<User> list = userMapper.selectByExample(example);
    for (User user : list) {
        user.setPassword("*****");
        user.setAnswer("****");
    }
    return list;
}
Also used : User(com.hfut.entity.User) UserExample(com.hfut.entity.UserExample)

Example 5 with UserExample

use of com.hfut.entity.UserExample in project Workload by amoxu.

the class UserServiceImpl method getList.

@Override
public List<User> getList(int typeId, int page, int limit) throws Exception {
    UserExample example = new UserExample();
    UserExample.Criteria criteria = example.createCriteria();
    criteria.andLevelEqualTo(typeId);
    example.setLimit(limit);
    if (page != 0) {
        page -= 1;
    }
    example.setOffset(page);
    List<User> list = userMapper.selectByExample(example);
    for (User user : list) {
        user.setPassword("*****");
        user.setAnswer("****");
    }
    return list;
}
Also used : User(com.hfut.entity.User) UserExample(com.hfut.entity.UserExample)

Aggregations

User (com.hfut.entity.User)5 UserExample (com.hfut.entity.UserExample)5 CustomException (com.hfut.exception.CustomException)1 Test (org.junit.Test)1