当我实现Spring安全性的User类时,我得到了类转换异常.我想在MyUserDetails(id)中添加一些额外的细节,但我无法得到结果.
这个问题在这里得到解答,但后来两个我收到错误,不知道我在哪里失踪.
以下是我的代码:
SecurityConfig.java:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
@Qualifier("authenticationProvider")
AuthenticationProvider authenticationProvider;
@Autowired
DataSource dataSource;
@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth)
throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.passwordEncoder(passwordEncoder())
.usersByUsernameQuery(
"select username,password, enabled from users where username=?")
.authoritiesByUsernameQuery(
"select username, role from user_roles where username=?");
}
@Bean
public PasswordEncoder passwordEncoder() {
PasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.headers().cacheControl().and().xssProtection().and()
.frameOptions().and();
http.authorizeRequests()
.antMatchers("/sadmin/**")
.access("hasRole('ROLE_SADMIN')")
.antMatchers("/admin/**")
.access("hasRole('ROLE_ADMIN') or …Run Code Online (Sandbox Code Playgroud) 我在bootstrap模式中打开了ckeditor但是格式和大小下拉不能正常工作.当我点击大小或格式下拉它立即打开和关闭时,我读到它是ckeditor中的bootstrap模式的一个错误.我在网上找到了解决方案,但这不起作用.
解决方案我在网上发现并且没有工作: -
$.fn.modal.Constructor.prototype.enforceFocus = function() {
modal_this = this
$(document).on('focusin.modal', function(e) {
if (modal_this.$element[0] !== e.target && !modal_this.$element.has(e.target).length &&
!$(e.target.parentNode).hasClass('cke_dialog_ui_input_select') &&
!$(e.target.parentNode).hasClass('cke_dialog_ui_input_text')) {
modal_this.$element.focus()
}
})
};
Run Code Online (Sandbox Code Playgroud)
我从哪里调用jsp和ck编辑器:
$scope.emailMsgSetting = function(msgId, headerName) {
$ocLazyLoad.load({
name: 'emailSettingsModule',
files: ['/doc/jsp/portal/viewMessageSettings.js']
}).then(function() {
var url = makeURL("/doc/jsp/portal/viewMessageSettings.jsp?");
$scope.dataURL = url;
}, function(e) {
console.log(e);
});
}
Run Code Online (Sandbox Code Playgroud)
JSP我在哪里实现了ck编辑器
<div class="col-sm-11 nopadright" ng-if="showckeditor">
<textarea ng-model="$parent.msgTypeBody" ck-editor insert-tag="strTagName" height="ckEditorheight" extra-plugins= "strTagName"></textarea>
</div>
Run Code Online (Sandbox Code Playgroud)
谢谢..
我想在服务器启动时从数据库配置Authorize Requests值.目前我在Java类文件中给出了硬核值,有没有办法从数据库中读取相同内容.
以下是示例代码:
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**", "/signup", "/about").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/db/**").access("hasRole('ADMIN') and hasRole('DBA')")
.anyRequest().authenticated()
.and()
// ...
.formLogin();
}
Run Code Online (Sandbox Code Playgroud)
如何从数据库中读取url,例如:/ admin/**,而不是类文件中的硬编码值
经过搜索,我才知道 JPQL 中没有 Right Join。我看到有另一种方法可以使用 JPA 双向(不是右连接,而是使用 pojo 对象)来实现它,但是我在控制台中注意到一件事,它对数据库进行了多次调用,例如见下表。
Flat Table UserToFlat User
| Flat_ID | Flat No | | ID | Flat_ID | User_ID | | User_ID | Name |
| 1 | 101 | | 1 | 1 | 1 | | 1 | XYZ |
| 2 | 102 | | 2 | 2 | 2 | | 2 | PQR |
| 3 | 103 | | 3 | 3 | 3 | | 3 | …Run Code Online (Sandbox Code Playgroud) 我有两个表平和usertoflat我想从平面表获取所有数据与usertoflat表上的条件.
我正在使用JPA,但我没有在jpa中找到派生表查询是我的本机sql查询.
Table Flat
flat_id | flat_no | status
1 | 1001 | 1
2 | 1002 | 1
3 | 1003 | 1
4 | 1004 | 1
Table usertoflat
usertoflat_id | Name | flat_id | status
1 | ABC | 1 | 1
2 | ABC | 1 | 2
3 | XYZ | 2 | 1
4 | PQR | 3 | 1
Required output
flat_id | flat_no | Name
1 | 1001 | ABC
2 | …Run Code Online (Sandbox Code Playgroud) 我有一个数据表,我可以在其中选择多行onclick但是如何在点击按钮上选择所有行,同时所有行都用选择突出显示(你能不能给出当前页面选择的例子和所有页).我编写了一个代码来获取多个选定值.
Checkbox也会这样做但是如何获得选定的值.
以下是单选和多选的代码.
var oTable = $("#example").dataTable();
$('#example tbody').on('click', 'tr', function() {
$(this).toggleClass('selected');
});
Run Code Online (Sandbox Code Playgroud)
用于在按钮提交时获取所选值的代码.
var row = oTable.rows('.selected').data();
var jsonArr = "[";
if(row != null && row.length){
for (var i = 0; i < row.length; i++) {
var row1 = row[i]; // this will give me one row details
// row1[0] will give me column details
jsonArr = jsonArr + "{\"ID\":" + row1[0] + "},";
}
jsonArr = jsonArr + "]";
Run Code Online (Sandbox Code Playgroud) 我想在4名玩家中随机分配52张牌.我虽然我会将每张卡放入HashMap,因为hashmap是无序的和未排序的,然后遍历它并将第1张13张牌分配给玩家1,最后13张牌分配给玩家4.但是当我遍历hashmap时,值总是相同的,我希望每次迭代的值都应该是不同的.下面是使用6号和输出相同的例子.
public static void main(String[] args) {
Map<String,String> map = new HashMap<String,String>();
map.put("1", "one");
map.put("2", "two");
map.put("3", "three");
map.put("4", "four");
map.put("5", "five");
map.put("6", "six");
for(Iterator<Entry<String, String>> iterator = map.entrySet().iterator(); iterator.hasNext();){
Entry<String,String> entry = iterator.next();
System.out.print(entry.getKey()+" "+ entry.getValue() +"\n");
}
}
Output
3 three
2 two
1 one
6 six
5 five
4 four
Run Code Online (Sandbox Code Playgroud)
N次运行代码但输出在我的机器中始终相同.我希望每次运行都有不同的输出.请指教.
java ×3
jpa-2.0 ×2
spring-mvc ×2
ckeditor4.x ×1
collections ×1
datatables ×1
hibernate ×1
jpql ×1
jquery ×1
jsp ×1
mysql ×1
right-join ×1