我有一个构造的案例表angular.material
,我需要按日期添加排序.但我的日期是一种string
类型,所以排序不正确.如何覆盖默认mat-sort-header
行为.这有可能吗?
<div class="example-container mat-elevation-z8">
<mat-table #table [dataSource]="dataSource" matSort>
<!-- Reg Date Column -->
<ng-container matColumnDef="regDate">
<mat-header-cell *matHeaderCellDef mat-sort-header> Reg Date </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.regDate}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
</div>
Run Code Online (Sandbox Code Playgroud)
在TS方面:
sort: MatSort;
@ViewChild(MatSort)
set appBacon(sort : MatSort) {
this.sort = sort;
this.dataSource.sort = this.sort;
}
dataSource = new MatTableDataSource([]);
Run Code Online (Sandbox Code Playgroud) 我将所有秘密数据保存到 AWS Parameter Store 中,我的应用程序使用 docker-compose 运行,并尝试aws ssm get-parameters
在内部进行评估docker-compose.yaml
:
version: "3.7"
services:
db:
image: postgres
restart: always
volumes:
- /home/ec2-user/dbdata:/var/lib/postgresql/data
environment:
POSTGRES_USER: $$(aws ssm get-parameters --name DB_USERNAME --region eu-north-1 --output text --query Parameters[].Value)
POSTGRES_PASSWORD: $$(aws ssm get-parameters --name DB_PASSWORD --region eu-north-1 --output text --with-decryption --query Parameters[].Value)
POSTGRES_DB: $$(aws ssm get-parameters --name DB_NAME --region eu-north-1 --output text --query Parameters[].Value)
ports:
- 5432:5432
auth:
build: .
restart: always
environment:
DB_ENDPOINT: $$(aws ssm get-parameters --name DB_ENDPOINT --region eu-north-1 --output …
Run Code Online (Sandbox Code Playgroud) amazon-web-services docker docker-compose aws-parameter-store
Jacoco 插件丢失了 JUnit 测试,报告始终为 0%,但测试存在。我认为问题是我的pom.xml
。帮我找出错误。
也许它与插件冲突checkstyle
?
部分 Jacoco 设置:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.7.0.1746</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<reportFormat>plain</reportFormat>
<includes>
<include>**/*Test*.java</include>
<include>**/*IT*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.0</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration> …
Run Code Online (Sandbox Code Playgroud) 我有日期选择器,它应该通过复选框切换单击动态禁用和启用。来自库角材料 6 的所有组件。由于我对表单处理程序使用反应式方法,我不能简单地使用[disable]
指令。我得到了进一步的错误:
It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true
when you set up this control in your component class, the disabled attribute will actually be set in the DOM for
you. We recommend using this approach to avoid 'changed after checked' errors.
Example:
form = new FormGroup({
first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
last: new FormControl('Drew', Validators.required)
});
Run Code Online (Sandbox Code Playgroud)
我有想法直接在 TS 中替换FormContol
inside FormGroup …
我使用 spring cloud2.1.3.RELEASE
版本,我的项目是用它生成的,https://start.spring.io/
然后我正在尝试运行我得到的应用程序
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-02-27 03:13:29.131 ERROR 4328 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'currencyConversionController' defined in file [/Users/pavel/GitHub/spring-cloud/currency-conversion-service/target/classes/com/pravvich/controller/CurrencyConversionController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.pravvich.service.CurrencyExchangeServiceProxy': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget …
Run Code Online (Sandbox Code Playgroud) 我尝试配置 spring-boot-security 以与我的 SQL 模式集成:
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
username VARCHAR(20) UNIQUE NOT NULL,
password VARCHAR(20) UNIQUE NOT NULL,
role INTEGER NOT NULL,
FOREIGN KEY (role) REFERENCES user_role (id)
);
CREATE TABLE IF NOT EXISTS user_role (
id SERIAL PRIMARY KEY,
role VARCHAR(10)
);
Run Code Online (Sandbox Code Playgroud)
我找到了许多使用 spring-boot-security 集成数据库的示例,所有这些示例如下:
@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery(
"select username,password, enabled from users where username=?")
.authoritiesByUsernameQuery(
"select username, role from user_roles where username=?");
} …
Run Code Online (Sandbox Code Playgroud) 不要使用servlet进行.jsp
连接.
我有doPost
servlet:
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF8");
getUser(req, resp);
}
private void getUser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getParameter("id");
//In future implements database worker this for check
User user = new User(1, "test", "test", "test", new Timestamp(System.currentTimeMillis()));
req.setAttribute("user", user);
req.getRequestDispatcher("user.jsp").forward(req, resp);
}
Run Code Online (Sandbox Code Playgroud)
以及在网页上user.jsp
使用User
对象进行查看的文件:
<h1>User view</h1><br />
<ul>
<% User user = (User) request.getSession().getAttribute("user"); %>
<li>Id: <% user.getId(); %></li>
<li>Name: <% user.getName(); %></li>
<li>Login: …
Run Code Online (Sandbox Code Playgroud) 我有一个简单的代码示例,其中我尝试从父组件数据发送到子组件,并在数据将被更改时同时从子组件到父组件获取数据:
上级:
@Component({
selector: 'app-parent',
templateUrl: './parent.component.html',
styleUrls: ['./parent.component.css']
})
export class ParentComponent {
parentData:string = 'start value'
}
<app-child [childData]="parentData"></app-child>
Run Code Online (Sandbox Code Playgroud)
儿童:
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css']
})
export class ChildComponent {
@Input() childData: string;
}
<p>
{{childData}}
<br>
<input [(ngModel)]="childData" type="text">
</p>
Run Code Online (Sandbox Code Playgroud)
我需要注释@Output()
, childData
但已经用注释了@Input()
。如何绑定变量childData
和parentData
?
页面有一个按钮,可以使用代码将文本复制到剪贴板:
export class ClipboardService {
static copyToClipboard(toCopy: string) : void {
document.addEventListener('copy', (e : ClipboardEvent) => {
e.clipboardData.setData('text/plain', toCopy);
e.preventDefault();
});
document.execCommand('copy');
}
}
Run Code Online (Sandbox Code Playgroud)
但是在使用后,此代码Ctrl+C
不起作用。我需要removeEventListener
类似的东西:
export class ClipboardService {
static copyToClipboard(toCopy: string) : void {
document.addEventListener('copy', (e : ClipboardEvent) => {
e.clipboardData.setData('text/plain', toCopy);
e.preventDefault();
});
document.execCommand('copy');
document.removeEventListener('copy', (e : ClipboardEvent) => {
e.clipboardData.??? // I stuck in this place.
});
}
}
Run Code Online (Sandbox Code Playgroud)
复制特定字段中的文本时如何返回剪贴板的标准行为?
Docker-compose 包含 2 个容器。第一个是 Postgres 数据库,第二个是 Java Spring Boot 应用程序。为了运行,我进一步使用 docker-compose 配置文件:
docker-compose.yml
version: "3.7"
services:
db-service:
image: postgres
restart: always
volumes:
- /home/ec2-user/dbdata:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 1
POSTGRES_DB: auth
ports:
- 5432:5432
auth-service:
build: .
restart: always
depends_on:
- db-service
links:
- db-service
ports:
- 80:80
Run Code Online (Sandbox Code Playgroud)
我想用来/home/ec2-user/dbdata
包含数据库数据,毕竟数据是创建的。成功地。postgres容器的日志是:
PostgreSQL 初始化过程完成;准备开始 2021-01-07 01:36:16.786 UTC [1] 日志:在 x86_64-pc-linux-gnu 上启动 PostgreSQL 13.1 (Debian 13.1-1.pgdg100+1),由 gcc 编译 (Debian 8.3.0- 6) 8.3.0,64 位 2021-01-07 01:36:16.786 UTC [1] 日志:监听 IPv4 地址“0.0.0.0”,端口 5432 2021-01-07 …
我有一个映射器UserMapper
,它映射过滤器以供进一步的数据库选择。
@Mapper(uses = {RoleMapper.class})
public interface UserMapper {
@Mapping(source = "roleIds", target = "roles")
UserFilter toUserFilter(UserFilterDto dto);
}
@Mapper
public interface RoleMapper {
default List<Role> roleIdListToRoleList(List<Long> roleIds) {
return Objects.isNull(roleIds)
? Lists.newArrayList()
: roleIds.stream().map(id -> Role.builder().id(id).build()).collect(Collectors.toList());
}
}
}
Run Code Online (Sandbox Code Playgroud)
源DTO
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserFilterDto extends FilterDto {
@JsonProperty("username")
private String username;
@JsonProperty("isEnabled")
private Boolean isEnabled;
@JsonProperty("roleIds")
private List<Long> roleIds;
}
Run Code Online (Sandbox Code Playgroud)
目标对象
@Data
@Builder
class UserFilter {
private String username;
private …
Run Code Online (Sandbox Code Playgroud) java ×6
angular ×3
spring ×3
docker ×2
maven ×2
spring-boot ×2
jacoco ×1
javascript ×1
jsp ×1
mapstruct ×1
postgresql ×1
servlets ×1
spring-mvc ×1
typescript ×1