我正在使用 Angular 4。我想允许zipCode输入字段仅接受长度为 5 或 7 位的输入。
HTML 代码:
<md-input-container class="fill-width-input-wrap">
<input mdInput placeholder="Zip Code" formControlName="zipCode" minLength="5" maxLength="7" (keypress)="allowOnlyNumbers($event)" required>
<md-error *ngIf="clientInformationForm.controls['zipCode'].hasError('required')">
Please enter
<strong>valid zipcode</strong>
</md-error>
<md-error *ngIf="clientInformationForm.controls['zipCode'].hasError('minLength')">
zip code
<strong>minimum length is 5</strong>
</md-error>
</md-input-container>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Spring 的安全性获取当前登录的用户名,但该Principal对象返回 null。
这是我的 REST 控制器方法:
@RequestMapping("/getCurrentUser")
public User getCurrentUser(Principal principal) {
String username = principal.getName();
User user = new User();
if (null != username) {
user = userService.findByUsername(username);
}
return user;
}
Run Code Online (Sandbox Code Playgroud)
注意:我正在运行 Spring boot 1.5.13 和 spring security 4.2.6
这是我的安全配置类:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Autowired
private Environment env;
@Autowired
private UserSecurityService userSecurityService;
private BCryptPasswordEncoder passwordEncoder() {
return SecurityUtility.passwordEncoder();
}
private static final String[] PUBLIC_MATCHERS = {
"/css/**",
"/js/**",
"/image/**",
"/book/**",
"/user/**"
}; …Run Code Online (Sandbox Code Playgroud)我正在用java编写一个csv文件,我想用'|'编写csv文件 作为分隔符。我该怎么做我的代码。
public void createCsv(User user) {
try( FileWriter writer = new FileWriter(CSV_FILE_NAME,true);
CSVWriter csvWriter = new CSVWriter(writer,
CSVWriter.DEFAULT_SEPARATOR,
CSVWriter.NO_QUOTE_CHARACTER,
CSVWriter.DEFAULT_ESCAPE_CHARACTER,
CSVWriter.DEFAULT_LINE_END);
CSVReader reader = new CSVReader(new FileReader(CSV_FILE_NAME));){
if(reader.readNext() !=null) {
csvWriter.writeNext(new String[]{user.getFirstName(), user.getLastName()});
}else {
String[] headerRecord = {"First Name", "Last Name"};
csvWriter.writeNext(headerRecord);
csvWriter.writeNext(new String[]{user.getFirstName(), user.getLastName()});
}
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在比较两个字符串,我想在比较之前将一个字符串小写.我怎样才能做到这一点?这是我的代码:
this.products = response.responseData.sort(function(a,b){
if(a.product.productName < b.product.productName){
return -1;
}
if(a.product.productName > b.product.productName){
return 1;
}
return 0;
});
Run Code Online (Sandbox Code Playgroud)