struts2.2.1+hibernate3.6.0+spring3.0.5+proxool-0.9.1实例(6)

service代码:
package com.yj.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;


import com.yj.dao.UserDAO;
import com.yj.model.User;
@Component
public class UserService {
	private UserDAO userDAO = new UserDAO();;

	public UserDAO getUserDAO() {
		return userDAO;
	}
	@Resource
	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public void save(User user) {
		userDAO.save(user);
	}
	
	public boolean exits(String username){
		List<User> users = userDAO.findByUsername(username);
		if(users!=null&&users.size()>0){
			return true;
		}
		return false;
	}
}


model:
package com.yj.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "User1")
public class User
{
    
    private String id;
    
    private String username;
    
    private String password;
    
    @Id
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @GeneratedValue(generator = "uuid")
    public String getId()
    {
        return id;
    }
    
    public void setId(String id)
    {
        this.id = id;
    }
    
    public String getUsername()
    {
        return username;
    }
    
    public void setUsername(String username)
    {
        this.username = username;
    }
    
    public String getPassword()
    {
        return password;
    }
    
    public void setPassword(String password)
    {
        this.password = password;
    }
}


你可能感兴趣的:(DAO,Hibernate)