Search in sources :

Example 1 with ServerException

use of com.cas.sim.tis.services.exception.ServerException in project TeachingInSimulation by ScOrPiOzzy.

the class UserServiceImpl method login.

@Override
public User login(String usercode, String password) {
    Condition condition = new Condition(User.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("code", usercode);
    criteria.andEqualTo("password", password);
    criteria.andEqualTo("del", 0);
    List<User> user = null;
    try {
        user = mapper.selectByCondition(condition);
    } catch (Exception e) {
        throw new ServerException("服务器异常", e);
    }
    if (user.size() == 1) {
        return user.get(0);
    } else if (user.size() == 0) {
        throw new ServiceException("用户名或密码错误!");
    } else {
        throw new TooManyResultsException();
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) User(com.cas.sim.tis.entity.User) ServerException(com.cas.sim.tis.services.exception.ServerException) ServiceException(com.cas.sim.tis.services.exception.ServiceException) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) Criteria(tk.mybatis.mapper.entity.Example.Criteria) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) ServiceException(com.cas.sim.tis.services.exception.ServiceException) ServerException(com.cas.sim.tis.services.exception.ServerException)

Aggregations

User (com.cas.sim.tis.entity.User)1 ServerException (com.cas.sim.tis.services.exception.ServerException)1 ServiceException (com.cas.sim.tis.services.exception.ServiceException)1 TooManyResultsException (org.apache.ibatis.exceptions.TooManyResultsException)1 Condition (tk.mybatis.mapper.entity.Condition)1 Criteria (tk.mybatis.mapper.entity.Example.Criteria)1