我花了一些时间研究 angularjs 的现有日期时间指令。
ngularUI 和 AngularStrap 都没有提供我需要的日期时间选择器。当然,我知道一起使用 datepicker 和 timepicker 来存档目的。
我已经从 Internet 和 stackoverflow 搜索了相关主题。发现了一些有趣且有用的信息。
http://dalelotts.github.io/angular-bootstrap-datetimepicker/,有一个 datetimepicker,但我不喜欢这个指令的用法。
将 datetimepicker 连接到 angularjs,这个主题非常有帮助,我尝试按照步骤包装我的 datetimepicker 指令。
我的工作基于https://github.com/Eonasdan/bootstrap-datetimepicker,一个基于 bootstrap 3 的 datetimepicker,UI 非常好。
app.directive('datetimepicker', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ngModelCtrl) {
console.log('call datetimepicker link...');
var picker = element.datetimepicker({
dateFormat: 'dd/MM/yyyy hh:mm:ss'
});
//ngModelCtrl.$setViewValue(picker.getDate());
//model->view
ngModelCtrl.$render(function() {
console.log('ngModelCtrl.$viewValue@'+ngModelCtrl.$viewValue);
picker.setDate(ngModelCtrl.$viewValue || '');
});
//view->model
picker.on('dp.change', function(e) {
console.log('dp.change'+e.date);
scope.$apply(function(){
ngModelCtrl.$setViewValue(e.date);
});
});
}
}; …Run Code Online (Sandbox Code Playgroud) 根据Spring Boot Docs,@TestConfiguration测试应自动检测嵌套。
但是在我的测试代码中,当我运行整个测试类时它是有问题的,即使我通过@Import. 测试代码结构如下:
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
//@Import(IntegrationTests.TestSecurityConfig.class)
public class IntegrationTests {
// test methods
// test configuration
@TestConfiguration
static class TestSecurityConfig {}
}
Run Code Online (Sandbox Code Playgroud)
当我单独运行单个测试用例(测试方法)时,所有测试都按预期通过,但是当我直接运行测试类时,有些测试失败了,@TestConfiguration没有应用于测试。
这样做的完整代码IntegrationTests是在这里。
更新:在我的代码中添加了一种解决方法以使测试通过。
@TestComponent
@Slf4j
static class TestUserDetailsService implements UserDetailsService {
private final PasswordEncoder passwordEncoder;
TestUserDetailsService(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
}
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UserDetails user = User.withUsername("user")
.password(passwordEncoder.encode("password"))
.roles("USER")
.accountExpired(false)
.accountLocked(false)
.credentialsExpired(false)
.disabled(false) …Run Code Online (Sandbox Code Playgroud) spring spring-test spring-test-mvc spring-boot spring-boot-test
我试图品尝 R2dbc 并使用嵌入式 H2,例如:
public ConnectionFactory connectionFactory() {
//ConnectionFactory factory = ConnectionFactories.get("r2dbc:h2:mem:///test?options=DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
return new H2ConnectionFactory(
H2ConnectionConfiguration.builder()
//.inMemory("testdb")
.file("./testdb")
.username("user")
.password("password").build()
);
}
Run Code Online (Sandbox Code Playgroud)
我定义了一个 bean 来创建表和初始化数据。
@Bean
public ConnectionFactoryInitializer initializer(ConnectionFactory connectionFactory) {
ConnectionFactoryInitializer initializer = new ConnectionFactoryInitializer();
initializer.setConnectionFactory(connectionFactory);
CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
populator.addPopulators(new ResourceDatabasePopulator(new ClassPathResource("schema.sql")));
populator.addPopulators(new ResourceDatabasePopulator(new ClassPathResource("data.sql")));
initializer.setDatabasePopulator(populator);
return initializer;
}
Run Code Online (Sandbox Code Playgroud)
而且我还定义了另一个组件来通过java代码设置数据。
@Component
@Slf4j
class DataInitializer {
private final DatabaseClient databaseClient;
public DataInitializer(DatabaseClient databaseClient) {
this.databaseClient = databaseClient;
}
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
log.info("start data initialization …Run Code Online (Sandbox Code Playgroud) spring-boot project-reactor spring-webflux spring-data-r2dbc r2dbc
我的示例代码基于 Spring Boot 2.4.0-M2(spring-data-r2dbc 1.2.0-M2)、Java 11、Postgres。
在 Spring 博客和更改日志中,它删除了 Spring Data R2dbc 获得了审计支持。
我像这样启用了审核。
@Configuration
@EnableR2dbcAuditing
class DataConfig {
@Bean
ReactiveAuditorAware<String> auditorAware() {
return () -> Mono.just("hantsy");
}
}
Run Code Online (Sandbox Code Playgroud)
以及实体类和存储库。
interface PersonRepository extends R2dbcRepository<Person, UUID> {
}
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(value = "persons")
class Person {
@Id
@Column("id")
private UUID id;
@Column("first_name")
private String firstName;
@Column("last_name")
private String lastName;
@Column("created_at")
@CreatedDate
private LocalDateTime createdAt;
@Column("updated_at")
@LastModifiedDate
private LocalDateTime updatedAt;
@Column("version")
@Version
private Long version;
}
Run Code Online (Sandbox Code Playgroud)
架构脚本。(不用担心 UUID,在 docker …
postgresql spring-data spring-boot spring-webflux spring-data-r2dbc
我尝试过JSF 2.3的新特性,其中一个吸引人的就是websocket。
我已经阅读了 mojarra 测试和 JSF 2.3 特定@Pushjavadoc 中的一些示例代码。
f:websocket并且在使用时遇到了一些问题f:ajax。
Facelets 模板是:
<h:panelGroup id="messagePanel" layout="block">
<ul>
<ui:repeat value="#{ajaxBean.messages}" var="m">
<li>#{m}</li>
</ui:repeat>
</ul>
</h:panelGroup>
<h:form id="form">
<h:commandButton
id="sendMessage"
action="#{ajaxBean.sendMessage()}"
value="Send Ajax Message">
<f:ajax/>
</h:commandButton>
</h:form>
<h:form>
<f:websocket channel="ajaxChannel" scope="view">
<f:ajax event="ajaxEvent" render=":messagePanel" />
</f:websocket>
</h:form>
<h:form>
<f:websocket channel="ajaxListenerChannel" scope="view">
<f:ajax event="ajaxListenerEvent" listener="#{ajaxBean.ajaxPushed}" render=":messagePanel" />
</f:websocket>
</h:form>
<f:websocket channel="commandScriptChannel" scope="view" onmessage="onCommandScript"/>
<h:form>
<h:commandScript name="onCommandScript" action="#{ajaxBean.commandScriptExecuted()}" render=":messagePanel"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
后端 bean 是:
@ViewScoped
@Named("ajaxBean")
public class AjaxBean implements Serializable …Run Code Online (Sandbox Code Playgroud) 我尝试升级我的测试以使用 TestContainers 和 Spring @DynamicPropertySource。
@Container
static Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.0")
.withStartupTimeout(Duration.ofMinutes(5));
@DynamicPropertySource
static void neo4jProperties(DynamicPropertyRegistry registry) {
registry.add("org.neo4j.driver.uri", neo4jContainer::getBoltUrl);
registry.add("org.neo4j.driver.authentication.username", () -> "neo4j");
registry.add("org.neo4j.driver.authentication.password", neo4jContainer::getAdminPassword);
}
Run Code Online (Sandbox Code Playgroud)
当我运行示例测试并得到以下异常时,测试开始时 Neo4j docker 似乎尚未准备好。
java.lang.IllegalStateException: Error processing condition on org.neo4j.driver.springframework.boot.autoconfigure.DriverConfiguration.neo4jDriver
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:184) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:144) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE] …Run Code Online (Sandbox Code Playgroud) 我试图测试 vertx munity web 客户端提供的反应式 web 客户端。
我遵循了官方指南Quarkus - Getting Started with Reactive。
并在依赖项中添加了以下内容。
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-mutiny-vertx-web-client</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但是当我Vertx像文章中提到的那样注入时,得到了 CDI 不满意的依赖异常。Vertx不可用。
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type io.vertx.mutiny.core.Vertx and qualifiers [@Default]
- java member: com.example.PostResourceClient#vertx
Run Code Online (Sandbox Code Playgroud)
完整的代码在这里。
reactive-programming vert.x quarkus smallrye quarkus-rest-client
目前,我正在使用Firebase Admin SDK连接NodeJS服务器端应用程序中的Firebase数据库.
但我找不到通过代理设置连接Firebase的选项,或者它可以检测我的系统HTTP_PROXY环境变量.
当我运行节点脚本时node index.js,得到一些这样的超时消息(我知道在我的工作网络中,我无法直接连接到Firebase).
Error: Credential implementation provided to initializeApp() via the "credential
" property failed to fetch a valid Google OAuth2 access token with the following
error: "connect ETIMEDOUT 216.58.200.237:443".
at ....erver\node_modules\firebase-adm
in\lib\firebase-app.js:74:23
at process._tickCallback (internal/process/next_tick.js:103:7)
Run Code Online (Sandbox Code Playgroud)
我也使用浏览器通过代理访问firebase控制台,它的工作原理.
但是如何在NodeJS服务器端脚本中解决这个问题?
proxy node.js firebase firebase-realtime-database firebase-admin
我刚刚尝试了Java 13中的新文本块功能,但遇到了一个小问题。
我已经从Jaxcenter阅读了这篇文章。
右三引号将影响格式。
String query = """
select firstName,
lastName,
email
from User
where id= ?
""";
System.out.println("SQL or JPL like query string :\n" + query);
Run Code Online (Sandbox Code Playgroud)
上面的格式效果很好。为了与结束定界符(“”“)对齐,多行字符串在每行之前保留空格。
但是,当我尝试比较以下两个文本块字符串时,它们在输出控制台中的格式相同,但是即使在之后也不相等stripIntent。
String hello = """
Hello,
Java 13
""";
String hello2 = """
Hello,
Java 13
""";
System.out.println("Hello1:\n" + hello);
System.out.println("Hello2:\n" + hello);
System.out.println("hello is equals hello2:" + hello.equals(hello2));
System.out.println("hello is equals hello2 after stripIndent():" + hello.stripIndent().equals(hello2.stripIndent()));
Run Code Online (Sandbox Code Playgroud)
输出控制台类似于:
String query = """
select firstName,
lastName,
email …Run Code Online (Sandbox Code Playgroud) 我将所有与数据库相关的操作移动到一个独立的模块中:
@Module({
imports: [
TypeOrmModule.forFeature([
PostRepository,
UserRepository,
CommentRepository,
]),
],
exports: [PostRepository, UserRepository, CommentRepository],
providers: [PostsDataInitializer],
})
export class DatabaseModule {}
Run Code Online (Sandbox Code Playgroud)
但是在其他模块中,当我导入DatabaseModule并尝试注入PostRepository服务类时,出现以下错误。
Nest cannot export a provider/module that is not a part of the currently processed module (DatabaseModule).
Please verify whether the exported PostRepository is available in this particular context.
Run Code Online (Sandbox Code Playgroud) 我正在阅读“ 切片之旅”,在“ 切片长度和容量”部分中,运行了示例:
package main
import "fmt"
func main() {
s := []int{2, 3, 5, 7, 11, 13}
printSlice(s)
// Slice the slice to give it zero length.
s = s[:0]
printSlice(s)
// Extend its length.
s = s[:4]
printSlice(s)
// Drop its first two values.
s = s[2:]
printSlice(s)
}
func printSlice(s []int) {
fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
}
Run Code Online (Sandbox Code Playgroud)
当我构建应用程序并运行它时,它显示如下:
len=6 cap=6 [2 3 5 7 11 13]
len=0 cap=6 []
len=4 cap=6 [2 3 …Run Code Online (Sandbox Code Playgroud) spring-boot ×4
ajax-update ×1
angularjs ×1
arrays ×1
firebase ×1
go ×1
java ×1
java-13 ×1
javascript ×1
jls ×1
jsf ×1
neo4j ×1
nestjs ×1
node.js ×1
postgresql ×1
proxy ×1
quarkus ×1
r2dbc ×1
slice ×1
smallrye ×1
spring ×1
spring-data ×1
spring-test ×1
string ×1
typeorm ×1
vert.x ×1
websocket ×1