我想使用彈簧安全,但我從來沒有在它之前使用過。我想從我的表(用戶,角色和user_roles)檢索用戶和角色。我有調查了大約用戶 - 用戶名 - 查詢。在所有示例中都與以下示例相同。春季安全用戶通過用戶名查詢與id_user
<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 username, role from user_roles where username =? " />
</authentication-provider>
</authentication-manager>
但我想用id_user和id_role,而不是用戶名和作用。可能嗎 ?我必須更改登錄頁面字段名稱嗎? 在此先感謝
這裏是一個關於它的很好的討論https://stackoverflow.com/questions/9069019/user-by-username-query-needing-more-than-1-parameter –
爲什麼你不檢索您的領域'id_user'和'id_role',並在相同的查詢中只是一個別名?這可能是實現這一目標的最簡單方法。從來就做了好幾次:'用戶按用戶名查詢=「\t選擇user.user_login作爲用戶名,user.user_pwd作爲密碼,user.user_enabled從用戶啓用其中user.user_login =?」' – jlumietu
確定,如果它可以像你說的那樣使用,我會嘗試一下。謝謝你的回覆。 –