Demo entry 6745415

Java

   

Submitted by anonymous on May 27, 2018 at 04:25
Language: Java. Code size: 438 Bytes.

public TbUserEntity getByUserName(String name) {
        //1.获得Session
        Session session = HibernateUtil.getSession();
        //2.书写HQL
        String hql = "from TbUserEntity where userName = ?";
        //3.创建查询对象
        Query query = session.createQuery(hql);
        //4.设置参数
        query.setParameter(0,name);
        //5.执行查询
        TbUserEntity u = (TbUserEntity) query.uniqueResult();
        return u;
    }

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).