Code: Select all
@Entity(name = "user")
@Table(name = "user")
public class User {
@Id
@Column(name = "id")
private String id;
@Column(name = "password")
private String password;
//getter and setter for this..
}
Code: Select all
public class UserDao {
public interface UserDAO {
public String insert(User user);
}
}
Sehen Sie, das war mein Code. Bitte überprüfen Sie ihn und sagen Sie mir, was ich falsch mache
Code: Select all
@Repository
@Transactional
public class UserImpl implements UserDAO {
private DataSource dataSource;
@Autowired
SessionFactory sessionFactory;
@Resource(name = "sessionFactory")
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public String insert(User use) {
Session session = this.sessionFactory.openSession();
try{
Session sess = this.sessionFactory.getCurrentSession();
session.save(reg);
return (String)user.getUserName();
}catch(Exception e){
System.out.println("in catch"+e.getMessage());
e.printStackTrace();
}
}
}
}
Code: Select all
userDao.insert(user);
Code: Select all
Mobile version