User Activation
Most of website we use while we want to make it, they may want you to register . of course, this is real good not just for them but for you, you can have your own space and more convenient to use it .as a soft engineer, there is a one thing I want to share with you, after you register, you want to make sure you are succeed or not, their website may have the function will send you a message to help you to confirm it which we call it “User Activation”.
【Here is the business logic】
Search the User from the activation number :(1)Check the user exist or not,if it exist then ;
Alert the user state as 1;
Activation number has change.
【Following is the code】
【UserDao.java】
//根据激活码查询用户
public User findByCode(String code){
String hql="from User where conde=?";
List<User>list =this.getHibernateTemplate().find(hql,code);
if(list !=null && list.size()>0){
return list.get(0);
}
return null;
}
//修改用户状态方法
public void update (User existUser){
this.getHibernateTemplate().update(existUser);
}
【UserAction.java】
/**
* 用户激活的方法
* Daniel.He
*/
public void active(){
//根据激活码查询用户
User existUser = userService.findByCode(user.getCode());
//判断
if(existUser==null){
//激活错误的
this.addActionMessage("激活失败:激活码错误!");
}else{
//激活成功
//修改用户状态
existUser.setState(1);
existUser.setCode(null);
userService.update(existUser);
this.addActionMessage("激活成功:请去登录!");
}
}
【UserService.java】
//业务根据激活码查询用户
public User findByCode(String code) {
// TODO Auto-generated method stub
return userDao.findByCode(code);
}
//修改用户状态的方法
public void update(User existUser) {
// TODO Auto-generated method stub
userDao.update(existUser);
}
As you can see the code above, you will got a “bingo”! here is the what we call it “code library”, this kind of code can use in another function or system is real useful.Have you got the desire to want to have a try, ready go.