我修改为字符串拼接就可以,如果用参数需要做什么配置吗?
String queryString = "from FmUser as model where model."
+ propertyName + "= '"+value+"'";
修改成这样就可以。

解决方案 »

  1.   

    如果你喜欢注解,把seesionFactory中的属性 
    <property name="annotatedClasses">
                <list>
                    <value>com.fundclien.entity.FmUser</value>
                </list>
     </property>
    改成
    <property name="packagesToScan">
    <value>com.fundclien.entity</value>
    </property>
    你也不嫌累,一个一个加~
      

  2.   

    queryObject.setParameter(0, value);这个value应该是FmUser类型,通过返回去get 对应的propertyName。
      

  3.   

    感谢 lmj623565791
    我已经按你指教的改了,果然好用啊。to 版主大人 fangmingshijie
    findByProperty(String propertyName, Object value) 是自动生成的,value是propertyName的值。
      

  4.   

    你这样试一下:String queryString = "from FmUser as model where model."
                        + propertyName + "=:value";
                Query queryObject = getCurrentSession().createQuery(queryString);
                queryObject.setParameter("value", value);
      

  5.   

    还有一个问题:
    我在loginAction的execute函数执行完成后,在跳转页面时报了个错误:
    HTTP Status 404 - No result defined for action com.fundclient.actions.loginA
    public String   execute() throws Exception{  
         boolean res = fmUserDao.validUser(userName, passWord);
            if(res){  
                   return SUCCESS;  
              }else{  
                   return ERROR;  
                }  
        }
    structs2.xml配置:<?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
    <struts>
    <constant name="struts.objectFactory" value="spring"></constant>  
    <package name="mypack" extends="struts-default">
        <action name="index">
                <result>/index.jsp</result>
            </action>
            <action name="login" class="com.fundclient.actions.LoginAction">  
             <result name="success">/index.jsp</result>
                <result name="error">/login.jsp</result>  
            </action>  
         </package>  
    </struts>    
      

  6.   


    不行也,还是会报错,这是不是hibernate4的bug啊,或者是不是需要配置什么参数来技能呀
      

  7.   

    action com.fundclient.actions.loginA这个action没有result的返回页面,楼主检查下这个action的配置
      

  8.   

    :-) 我写错了,错误消息是No result defined for action com.fundclient.actions.loginAction and result error
      

  9.   

    1.参数绑定这个还没有解决。
    2.访问已经解决了
    <action name="login" class="com.fundclient.actions.loginAction" method="execute">
    改成
    <action name="loginAction" class="com.fundclient.actions.loginAction" method="execute">
    就好了。