SSH框架增删改查的代码怎么写?

 我来答
匿名用户
2013-07-07
展开全部
import javax.annotation.Resource;import org.hibernate.Session;
import org.hibernate.SessionFactory;public class BaseDao {
@Resource
private SessionFactory sessionFactory;

protected Session getSession(){
return sessionFactory.getCurrentSession();
}
} import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;import org.leadfar.mms.dao.MessageDao;
import org.leadfar.mms.model.Message;
import org.leadfar.mms.model.User;
import org.leadfar.mms.model.ReceiveMessage;
import org.springframework.stereotype.Repository;@Repository("messageDao")
public class MessageDaoImpl extends BaseDao implements MessageDao { @Override
public Message getMessage(int id) {

return (Message)getSession().load(Message.class, id);
} @Override
public ReceiveMessage getReceiveMessage(int id) { return (ReceiveMessage)getSession().load(ReceiveMessage.class, id);
} @Override
public List<ReceiveMessage> queryReceiveBox(User receiver) {
String hql="select r from ReceiveMessage r where r.receiver.id = ? and r.receiverDel = ?";
List<ReceiveMessage> receiveMessages = getSession().createQuery(hql).setParameter(0, receiver.getId()).setParameter(1, false).list();
return receiveMessages;
} @Override
public List<ReceiveMessage> queryRubbishBox(User user) {
String hql = "from ReceiveMessage where (receivemessage.sender.id = ? or receiver.id = ?) and ( receivemessage.senderDel= ? or receiverDel = ?)";
List<ReceiveMessage> receiveMessages = getSession().createQuery(hql).setParameter(0, user.getId()).setParameter(1, user.getId()).setParameter(2, true).setParameter(3, true).list();
return receiveMessages;
} @Override
public List<Message> querySendBox(User sender) {
String hql = "from Message m where m.sender.id = ? and m.senderDel = ?";
List<Message> sendMessages = getSession().createQuery(hql).setParameter(0, sender.getId()).setParameter(1, false).list();
return sendMessages;
} @Override
public void save(Message message) {
getSession().save(message);

} @Override
public void save(ReceiveMessage rm) {
getSession().save(rm);
} @Override
public void update(Message message) {
getSession().update(message);

} @Override
public void update(ReceiveMessage um) {
getSession().update(um);
} @Override
public void delete(ReceiveMessage rm) {
getSession().delete(rm);
} @Override
public void delete(Message message) {
getSession().delete(message);
}}
刚刚正做一个SSH模块呢,有可以发给你让你学习学习
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式