2012-12-05 42 views
0

當我試圖用彈簧安全通過數據庫來驗證,我用Google搜索了幾個例子,它們都類似這樣的疑問:Spring jdbc SQL糟糕的語法異常,是選擇列嚴格嗎?

<authentication-manager> 
    <authentication-provider> 
    <jdbc-user-service data-source-ref="dataSource" 

     users-by-username-query=" 
      select username,password, enabled 
      from users where username=?" 

     authorities-by-username-query=" 
      select u.username, ur.authority from users u, user_roles ur 
      where u.user_id = ur.user_id and u.username =? " 

    /> 
    </authentication-provider> 
</authentication-manager> 

是錯的,如果我將改變查詢類似如下?如果不是爲什麼?

<security:authentication-manager> 
    <security:authentication-provider> 
      <security:jdbc-user-service data-source-ref="dataSource" 
       users-by-username-query="select login.name,login.passw from login where login.name=?" 
      authorities-by-username-query="select login.name, login.type from login where login.name =?"/> 

    </security:authentication-provider> 
</security:authentication-manager> 

這個例子給出了一個不好的SQL異常。

回答

1

您可以使用別名:

users-by-username-query="select login.name username,login.passw password from login where login.name=?" 

但我認爲你需要enabled了。如果你不在數據庫中,你可以在查詢中將它硬編碼爲真。