User user=dao.findUserByCode(code);

package com.itheima.tfy.service.impl;


import java.util.UUID;


import com.itheima.tfy.dao.UserDao;
import com.itheima.tfy.dao.impl.UserDaoImpl;
import com.itheima.tfy.domain.User;


public class UserServiceImpl {
private UserDao dao=new UserDaoImpl();
//激活码由上一层传过来
public void regist(User user){
if(user.getCode()!=null &&user.getCode().equals("")){
throw new RuntimeException("激活码没有传过来");
}
user.setId(UUID.randomUUID().toString());
dao.addUser(user);

}
public void actived(String code){
User user=dao.findUserByCode(code);
if(user==null)
throw new RuntimeException("激活码有误");
user.setActived(true);
dao.update(user);
}
/**
* 登录
* @param username
* @param password
* @return 用户名或密码错误 或没有激活码都返回null
*/
public User login(String username,String password){
User user=dao.findUser(username, password);
//判断是否激活
if(user!=null){
if(!user.isActived()){
user=null;
}
}
return user;
}
}

你可能感兴趣的:(User user=dao.findUserByCode(code);)