我有一个返回字节 [] 的 api,我想在我的前端应用程序中将它显示为图像,所以我使用数据 url 来显示图像
this.cardBackgroundService.getImage(event.data.entitlementCertificateNumber, "C003").subscribe(data => {
this.image = data;
console.log(this.image);
});
<img src="data:image/png;base64,{{image}}"/>
Run Code Online (Sandbox Code Playgroud)
问题是当我在控制台中显示 api 的响应时,它具有这种格式并且不显示为图像
?PNG ?Ou???j?000000000H??a
??a````````??a??a??a```````??a??a??a````````??a??a??a```````??a??a````````?.r? ?? ??X??V??QS??\?????F?`?{lhXnJU??s??ii??O1?;??????
启动我的应用程序时遇到问题。有人可以帮我解决这个问题吗?
Parameter 0 of constructor in com.journaldev.elasticsearch.service.BookServiceImpl required a bean of type 'com.journaldev.elasticsearch.dao.search.BookRepositorySearch' that could not be found.
Action:
Consider defining a bean of type 'com.journaldev.elasticsearch.dao.search.BookRepositorySearch' in your configuration.
Run Code Online (Sandbox Code Playgroud)
通用存储库
public interface GenericRepository<T, K> {
Map<String, Object> get(final K id);
}
Run Code Online (Sandbox Code Playgroud)
GenericRepositoryImpl
public class GenericRepositoryImpl<T, K extends Serializable> implements GenericRepository<T, K> {
private RestHighLevelClient restHighLevelClient;
private ObjectMapper objectMapper;
public GenericRepositoryImpl(ObjectMapper objectMapper, RestHighLevelClient restHighLevelClient) {
this.objectMapper = objectMapper;
this.restHighLevelClient = restHighLevelClient;
}
@Override
public Map<String, Object> get(K id) {
return null; …Run Code Online (Sandbox Code Playgroud) 我使用 postgres 配置了 debezium,如下代码所示,当我启动 Spring Boot 应用程序时出现错误Creation of replication slot failed
@Bean
public io.debezium.config.Configuration connector() {
return io.debezium.config.Configuration.create()
.with(EmbeddedEngine.CONNECTOR_CLASS, PostgresConnector.class)
.with(EmbeddedEngine.OFFSET_STORAGE, FileOffsetBackingStore.class)
.with(EmbeddedEngine.OFFSET_STORAGE_FILE_FILENAME, "offset.dat")
.with(EmbeddedEngine.OFFSET_FLUSH_INTERVAL_MS, 60000)
.with("name", "test-postgres-connector")
.with(RelationalDatabaseConnectorConfig.SERVER_NAME, "172.26.113.123:5455-test")
.with(RelationalDatabaseConnectorConfig.HOSTNAME, "172.26.113.123")
.with(RelationalDatabaseConnectorConfig.PORT, "5455")
.with(RelationalDatabaseConnectorConfig.USER, "test")
.with(RelationalDatabaseConnectorConfig.PASSWORD, "test")
.with(RelationalDatabaseConnectorConfig.DATABASE_NAME, "test")
.with(RelationalDatabaseConnectorConfig.TABLE_INCLUDE_LIST, "question").build();
}
2021-04-02 12:58:56.817 ERROR 14672 --- [pool-5-thread-1] io.debezium.embedded.EmbeddedEngine : Unable to initialize and start connector's task class 'io.debezium.connector.postgresql.PostgresConnectorTask' with config: {name=student-postgres-connector, connector.class=io.debezium.connector.postgresql.PostgresConnector, database.port=5455, offset.storage=org.apache.kafka.connect.storage.FileOffsetBackingStore, table.include.list=question, database.user=pfe, database.hostname=172.26.113.123, offset.storage.file.filename=offset.dat, database.password=********, offset.flush.interval.ms=60000, database.server.name=172.26.113.123:5455-pfe, database.dbname=pfe}
io.debezium.DebeziumException: Creation of replication slot …Run Code Online (Sandbox Code Playgroud) 我在 Spring Boot 应用程序中使用 postgres 作为数据库,当我运行我的应用程序时出现错误FATAL: sorry, too many clients already。我在 application.yml 中配置了一个连接池,但我仍然有同样的问题
spring:
jpa:
database: postgresql
hibernate:
ddl-auto: update
datasource:
url: jdbc:postgresql://localhost:5432/sp
username: sp
password: admin
continueOnError: true
platform: dev
tomcat:
maxIdle: 10
max-active: 100
max-wait: 10000
validationQuery: select 1
removeAbandoned: true
removeAbandonedTimeout: 120
logAbandoned: true
testOnBorrow: true
testOnConnect: true
testWhileIdle: true
Run Code Online (Sandbox Code Playgroud)
2018-06-13 09:29:47.311 [ERROR] [main] [logging.DirectJDKLog:181] 无法创建池的初始连接。org.postgresql.util.PSQLException:致命:在 org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:443) 在 org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl( ConnectionFactoryImpl.java:217) 在 org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) 在 org.postgresql.jdbc.PgConnection.(PgConnection.java:215) 在 org.postgresql.Driver.makeConnection(Driver. java:404) 在 org.postgresql.Driver.connect(Driver.java:272) 在 org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) 在 org.apache.tomcat.jdbc.pool .PooledConnection。
我想输出一个表单,其中一个字段是一个数组,对于数组的每个元素,我需要输出我的输入。
成分:
ngOnInit() {
const fb = this.fb;
this.editForm = this.fb.group({
country: fb.control(null),
identifiers: this.fb.array([
this.fb.group({
codeIdentifier: fb.control(null),
numIdentifier: fb.control(null),
})
]),
});
this.organizationService.getOneById(this.id).subscribe((organization: Organization) => {
let ids: any[] = [];
organization.identifiers.forEach(item => {
let id: any = { "codeIdentifier": "", "numIdentifier": "" };
id.codeIdentifier = item.typeIdentifier.code;
id.numIdentifier = item.numIdentifier;
ids.push(id);
});
this.editForm.setControl('identifiers', this.fb.array(ids || []));
})
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div [formGroup]="editForm">
<ng-container formArrayName="identifiers">
<ng-container *ngFor="let identifier of identifiers.controls; let i=index" [formGroupName]="i">
<input type="text" formControlName="codeIdentifier">
<input type="text" formControlName="numIdentifier">
</ng-container>
</ng-container> …Run Code Online (Sandbox Code Playgroud) 我试图从日期中获取日期名称,但使用该日期27/02/2021我得到了无效日期
new Date(exam.examDate).toLocaleString('fr-FR', { weekday: 'long' })
Run Code Online (Sandbox Code Playgroud)
我尝试使用 datePipe 转换日期,但它返回以下错误
无法将“27/02/2021”转换为管道“DatePipe”的日期
new Date(this.datePipe.transform(exam.examDate, "dd/MM/yyyy")).toLocaleString('fr-FR', { weekday: 'long' })
Run Code Online (Sandbox Code Playgroud) 我有一个电子邮件输入,我希望当我在输入中写入大写字母时,它会将它们转换为小写字母
我尝试了这个方法,但它显示了一个错误
错误范围错误:超出最大调用堆栈大小
<input type="text" formControlName="mail" (ngModelChange)="toLowerCase($event)">
private toLowerCase(event): void {
this.cmOrganizationForm.get('mail').setValue(event.toLowerCase());
}
Run Code Online (Sandbox Code Playgroud) 我有一个对象学校,其中有一个对象人,人已经保存在数据库中,当我保存学校对象时,我给它一个人ID
因此在班级学校中,我有一个类型为Person的属性person,在SchoolDTO中,我有一个类型为Long的属性personId
@Mapper(componentModel = "spring", uses = { PersonMapper.class })
public interface SchoolMapper extends EntityMapper<SchoolDTO, School>{
@Mapping(source = "personId", target = "person")
School toEntity(SchoolDTO schoolDTO);
}
School school = schoolMapper.toEntity(schoolDTO);
log.info(school.getPerson());
public interface EntityMapper <D, E> {
E toEntity(D dto);
D toDto(E entity);
List <E> toEntity(List<D> dtoList);
List <D> toDto(List<E> entityList);
}
@Mapper(componentModel = "spring", uses = {})
public interface PersonMapper extends EntityMapper<PersonDTO, Person> {
default Person fromId(Long id) {
if (id == null) {
return null;
}
Person person= …Run Code Online (Sandbox Code Playgroud) 我有下面的约定列表,我想按专业过滤此列表,即当我输入15时,它返回id为1和2的约定
[
{
"id": 1,
"typeActivities": [
{
"id"=11,
"specialitiesId": [10, 15]
}
]
},
{
"id": 2,
"typeActivities": [
{
"id"=22,
"specialitiesId": [10]
},
{
"id"=222,
"specialitiesId": [15]
}
]
},
{
"id": 3,
"typeActivities": [
{
"id"=33,
"specialitiesId": [12]
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
我试过这个功能,但没有回报
let input: number = 15;
let convention: Convention[];
convention = this.conventions.filter(convention => {
let typeActivities: TypeActivity[] = convention.typeActivities.filter(typeActivitiy => {
if (typeActivitiy.specialitiesId) {
return input == typeActivitiy.specialitiesId.find(id => id == input);
}
});
//console.log(convention.typeActivities.map(i …Run Code Online (Sandbox Code Playgroud) 声纳向我显示了这个错误Performance - Method does not presize the allocation of a collection
方法映射(ResponseEntity)不会预先调整集合的分配
这是代码:
private Set<ResponseDTO> mapping(ResponseEntity<String> responseEntity) {
final Set<ResponseDTO> result = new HashSet<>();
final JSONObject jsonObject = new JSONObject(responseEntity.getBody());
final JSONArray jsonArray = jsonObject.optJSONArray("issues");
for (int i = 0; i < jsonArray.length(); i++) {
final JSONObject innerObject = jsonArray.getJSONObject(i);
final String name = innerObject.optString("key");
result.add(new ResponseDTO().name(name));
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
为什么 Sonar 将此标记为错误以及如何修复它?
我使用了 ng-bootstrap 中的模态
在我的父组件中,我曾经modalService打开模态,然后使用将数据发送到模态componentInstance。
在模态组件中,我用来ngOnChanges获取发送的数据。但未ngOnChanges触发。
父组件
public toAttach(): void {
let modalRef = this.modalService.open(HelloComponent);
modalRef.componentInstance.attachments = this.attachments;
}
Run Code Online (Sandbox Code Playgroud)
模态成分
ngOnChanges(changes: SimpleChanges) {
console.log("start!");
if (changes["attachments"] && changes["attachments"].currentValue) {
console.log(changes["attachments"].currentValue);
}
}
Run Code Online (Sandbox Code Playgroud) 我的服务中有一种方法可以在我的服务器中保存日期,当此方法将日期发送到服务器时,它会发送与 json 中的 null 相同的字段,如何删除具有 null 值的字段?
public create<T>(post: any): Observable<T> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
return this.httpClient
.post<T>(`${this.url}`, JSON.stringify(post), httpOptions)
.pipe(catchError((err, source) => this.responseHandler.onCatch(err, source)));
}
Run Code Online (Sandbox Code Playgroud)
json 发送到服务器:
{
"name": "test",
"professionType":{
"id": null
},
"comment": null,
"organizationSpecialities":[
{
"speciality":{
"id": null
},
"effective": 2,
"effectiveDate":{
"startDate": null,
"endDate": "2019/12/01"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想发送的json:
{
"name": "test",
"organizationSpecialities":[
"effective": 2,
"effectiveDate":{
"endDate": "2019/12/01"
}
}
]
}
Run Code Online (Sandbox Code Playgroud) angular ×6
typescript ×6
java ×3
postgresql ×2
spring-boot ×2
angular5 ×1
debezium ×1
javascript ×1
jdbc ×1
json ×1
mapstruct ×1
sonarqube ×1
spring ×1