在过去的几天里,我一直试图了解java泛型.据我所知,Java泛型不是协变的,因此List<Object>不能与其他泛型List的赋值兼容
但是在下面的程序中,nameAndPhone.collect()方法返回一个类型的List,List<NamePhone>当我用程序替换引用变量List<NamePhone> npList时List<Object> npList仍然编译而没有警告.
我尝试使用类似的方法返回List<String>,并使用List<Object>引用变量不会导致任何错误.
为什么List<Object>赋值与List<NamePhone>此兼容?
import java.util.*;
import java.util.stream.*;
class NamePhoneEmail
{
String name;
String phonenum;
String email;
NamePhoneEmail(String n, String p, String e)
{
name = n;
phonenum = p;
email = e;
}
}
class NamePhone
{
String name;
String phonenum;
NamePhone(String n, String p)
{
name = n;
phonenum = p;
}
}
public class CollectDemo …Run Code Online (Sandbox Code Playgroud) 我在我的 React Native 应用程序中使用下拉选择器,它在 Android 设备上工作正常,但 UI 在 ios 上中断
代码
import React, { Component } from 'react';
import { View, TouchableOpacity, Text, StyleSheet } from 'react-native';
import DropdownPicker from '../DropdownPicker';
import { Platform } from 'react-native';
import DropDownPicker from 'react-native-dropdown-picker';
import Icon from 'react-native-vector-icons/Feather';
export default class RadioButton extends Component {
state = {
value: null,
selectedPicker: null,
picker: 'No Minimum Duration',
itemsA: [
{ label: 'Owner for this place', value: 'opt1' },
{ label: 'France', value: 'france' }, …Run Code Online (Sandbox Code Playgroud) 当我尝试为使用以下命令生成的组件添加自动路由时
ng generate module orders --route orders --module app.module
Run Code Online (Sandbox Code Playgroud)
我收到错误
Couldn't find a route declaration in /src/app/app-routing.module.ts.
Run Code Online (Sandbox Code Playgroud)
应用程序路由.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Routes } from '@angular/router';
@NgModule({
declarations: [],
imports: [
CommonModule
]
})
export class AppRoutingModule {
}
Run Code Online (Sandbox Code Playgroud)
我还尝试将这一行添加到应用程序路由文件中
export const routes: Routes = []
Run Code Online (Sandbox Code Playgroud)
问题仍然存在。如何修复此错误?
我正在尝试学习Spring安全性。我曾BCryptPasswordEncoder先将用户密码编码,然后再保存到数据库中
:
@Override
public void saveUser(User user) {
user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
user.setActive(1);
Role userRole = roleRepository.findByRole("ADMIN");
user.setRoles(new HashSet<Role>(Arrays.asList(userRole)));
userRepository.save(user);
}
Run Code Online (Sandbox Code Playgroud)
然后在身份验证期间也使用它,并且用户已按预期进行身份验证。
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.
jdbcAuthentication()
.usersByUsernameQuery(usersQuery)
.authoritiesByUsernameQuery(rolesQuery)
.dataSource(dataSource).passwordEncoder(bCryptPasswordEncoder);
}
Run Code Online (Sandbox Code Playgroud)
然后我.passwordEncoder(bCryptPasswordEncoder);从configure()方法中删除,仍然使用密码编码的用户仍成功通过身份验证。
然后,我从saveUser()和configure()方法中都删除了密码编码器,并将a持久化User到数据库中(即不使用密码编码),并尝试访问经过身份验证的页面,但是我得到了AccessedDeniedException,
但是即使我passwordEncoder()从configure()方法中删除,使用编码密码的用户仍然可以通过身份验证。为什么会这样呢?
默认情况下,spring security是否在身份验证期间使用密码编码器?
如果是这样,如何在没有密码编码的情况下使用spring security?
我有一个订单表..每个表行代表一个订单实体,当用户单击特定行时,它应该重定向到包含单击订单详细信息的新视图。这两个组件不是父级和子级,我想将有关单击的订单行的数据传递到导航页面。我尝试了以下方法
<tr *ngFor="let order of allOrders" routerLink="../orderdetails" [state]=”{data:order}”>
<td>{{order.orderRef}}</td>
<td>{{order.receiptRef}}</td>
<td>{{order.customer}}</td>
<td>{{order.orderDate}}</td>
<td>{{order.salesMan}}</td>
<td>{{order.total}}</td>
<td>{{order.status}}</td>
<td>{{order.session}}</td>
<td>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
这会导致视图导航到 Orderdetails
ngOnInit(): void {
console.log(history.state)
console.log(history.state.data);
}
Run Code Online (Sandbox Code Playgroud)
在 ngOnInit()console.log(history.state)日志中,{navigationId: 1}
但console.log(history.state.data)logs undefined.
为什么我得到的undefined不是我在 上设置的数据state?
如何访问我传递给state属性的数据?
许多Java Stream接口方法在参数中使用下界通配符
例如
Stream<T> filter(Predicate<? super T> pred)
Run Code Online (Sandbox Code Playgroud)
和
void forEach(Consumer<? super T> action)
Run Code Online (Sandbox Code Playgroud)
Predicate<? super T>在Predicate<T>这里使用的好处是什么?
我知道,Predicate<? super T>可以将T和超级类型的谓词对象作为参数传递给方法,但是我无法想到在特定类型上需要超级类型的谓词的情况?
例如,如果我有一个Stream<Integer>i,则可以将Predicate<Integer>, Predicate<Number>, and Predicate<Object>对象作为参数传递给它的filter方法,但是为什么有人会传递Predicate<Object>over Predicate<Integer>?在这里
使用的好处是<? super T>什么?
我正在学习 spring 安全,我从https://spring.io/guides/tutorials/spring-boot-oauth2/ 中发现了这段代码
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**", "/webjars/**", "/error**")
.permitAll()
.anyRequest()
.authenticated();
}
Run Code Online (Sandbox Code Playgroud)
我删除.antMatcher("/**")了,代码仍然有效。我知道**匹配路径中的零个或多个目录,所以我认为antMatcher("/**").authorizeRequestes().antMatcher("/login")会"/login"直接或间接匹配根路径下的目录,即我希望它匹配路径/login,/demo/login但事实并非如此,它只匹配/login根路径正下方的目录。那么究竟需要.antMatcher("/**") here什么呢?
我正在用百里香学习弹簧靴。我已经在文件系统中存储了用户对象的配置文件图像,只有图像的 URL 是数据库中持久化用户对象的一部分。
我已将name和添加dpurl到模型中,以便从模板访问它。
@GetMapping("/profile")
public String profileController(@AuthenticationPrincipal User activeUser, Model model) {
model.addAttribute("name", activeUser.getName());
model.addAttribute("dpurl", activeUser.getDpURL());
return "profile";
}
Run Code Online (Sandbox Code Playgroud)
我可以使用name模板访问th:text="${name}"
但是,我无法像这样使用百里香叶指定背景图像
<div id="dp-container" th:style="'background-image: url(' + @?{dpurl} + ');'" >
Run Code Online (Sandbox Code Playgroud)
这导致错误
Could not parse as expression: "'background-image: url(' + @?{dpurl} + ');'"
更新
像这样改变它
<div id="dp-container" th:style="'background-image:url(' + @{dpurl} + ');'">
Run Code Online (Sandbox Code Playgroud)
现在我没有收到任何错误,但背景图像仍未显示。
如何使用 Thymeleaf 指定背景图像?
当我显式指定构造函数参数的访问说明符时,它在构造函数外部可见:
constructor(private employeResourceService:EmployeeResourceService ){
//code}
ngOnInit(){
this.employeResourceService=undefined;//possible
}
Run Code Online (Sandbox Code Playgroud)
但是当我删除 acces 说明符时,构造函数参数在构造函数外部不可见:
constructor(employeResourceService:EmployeeResourceService ){
//code}
ngOnInit(){
this.employeResourceService=undefined;//not visible
}
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?TypeScript 没有像 Java 那样的默认访问说明符?
我读过,数组的元素存储在连续的内存位置中。总是这样吗?我知道基元数组就是这种情况。我对对象数组有点困惑。对象数组基本上包含真实对象的引用,对吗?引用必须存储在连续的位置,但是真实的对象真的存储在连续的位置吗?
java ×5
angular ×3
spring ×3
spring-boot ×3
typescript ×3
generics ×2
java-stream ×2
javascript ×1
react-native ×1
thymeleaf ×1