我想利用在angular2观测和糊涂了,为什么我应该使用map()过subscribe().假设我从webApi获取值,就像这样
this.http.get('http://172.17.40.41:8089/api/Master/GetAllCountry')
Run Code Online (Sandbox Code Playgroud)
现在使用subscribe(success, error, complete)我可以获得成功回调的所有值,我可以返回完整回调的值.如果我可以做所有这些功能,那么需要map()什么?它有什么优势吗?
简而言之,为什么人们应该这样写:
this.http.get('http://172.17.40.41:8089/api/Master/GetAllCountry')
.map(r=>{})
.subscribe(value => {
}, error => error, () => {
});
Run Code Online (Sandbox Code Playgroud)
当他们可以简单地写这个没有map函数:
this.http.get('http://172.17.40.41:8089/api/Master/GetAllCountry')
.subscribe(value => {
}, error => error, () => {
});
Run Code Online (Sandbox Code Playgroud) 我试图让我的应用程序更好,代码更易于维护,Dagger2我抓住了一般的想法,但仍然无法弄清楚范围是如何管理Dagger2
我把dagger注入我的项目(听起来很有趣).我创建了ApplicationComonent组件,它在我的项目中完美运行.这是我的代码.
@Singleton
@Component(modules = {
ApplicationModule.class,
ThreadingModule.class,
NetworkModule.class,
DatabaseModule.class,
ServiceModule.class,
ParseModule.class,
PreferencesSessionModule.class})
public interface ApplicationComponent {
ActivityComponent activityComponent(ActivityModule activityModule);
void inject(BaseActivity baseActivity);
void inject(MainAppActivity mainAppActivity);
void inject(MyApplication application);
void inject(BaseFragment baseFragment);
void inject(MyService service);
void inject(RegistrationIntentService service);
}
Run Code Online (Sandbox Code Playgroud)
我在MyApplication类中创建我的组件实例
private void initializeAndInjectComponent() {
mApplicationComponent =
DaggerApplicationComponent
.builder()
.threadingModule(new ThreadingModule(1))
.applicationModule(new ApplicationModule(this))
.networkModule(new NetworkModule(
MyService.API_SERVER_BASE_URL,
MyService.TIMEOUT))
.build();
mApplicationComponent.inject(this);
}
Run Code Online (Sandbox Code Playgroud)
我可以获得组件以便注入我的 Activities
MyApplication application = MyApplication.get(this);
application.getApplicationComponent().inject(this);
Run Code Online (Sandbox Code Playgroud)
一切都很完美.
添加每个方法以及模块类都用@Singleton范围注释,所有模块都与之相关ApplicationComponent
现在我想更好地建立依赖关系,我已经看到很多自定义范围的例子,比如@PerActivity …
我有两个孩子div 20%和80%.最后一个包含嵌套的spans,如果文本不适合同一行,则它将在单行上移动到下一行(默认行为).
HTML:
<div class="post-short-footer">
<div class="read-more-post"></div>
<div class="post-short-meta-container">
<span class="posted-on"><i class="fa fa-calendar" aria-hidden="true">Some text</i></span>
<span class="cat-links"><i class="fa fa-folder-open-o" aria-hidden="true"></i>Some text</span>
<span class="comments-link"><i class="fa fa-comment-o" aria-hidden="true"></i></span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.post-short-footer {
display: table;
width: 100%;
}
.read-more-post {
height: 100%;
display: table-cell;
vertical-align: middle;
width: 20%;
padding: 0.6em 0.6em;
border-radius: 0.3em;
text-align: center;
border: 1px solid #3b9be5;
}
.post-short-meta-container {
display: table-cell;
padding-left: 1em;
width: 80%;
line-height: 100%;
vertical-align: middle;
height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
但是如果跨度中的文本不适合行移动整个跨度到下一行,我需要实现下一个结果.
我已经尝试过:
.post-short-meta-container span { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用HTTPS与自签名证书的连接.
我按照这里提到的创建自签名证书的步骤 - 创建自签名证书.
即使在浏览器中一切正常,它只向我显示我的证书由未知CA签名的消息.
但是我的证书中的FQDN(服务器名称不匹配)名称有问题,因为我在生成证书时设置了错误的名称.
我已经重新生成它,现在没有这样的错误.
我需要从移动Android客户端使用我的服务器sertificate,我找到了关于此问题的精彩文章 - 在Android中使用自签名或未知SSL证书的Retrofit.我已经遵循了所有步骤,但遗憾的是得到了一个错误(例外).
javax.net.ssl.SSLPeerUnverifiedException: Hostname 195.xx.xx.xx not verified:
certificate: sha1/qvH7lFeijE/ZXxNHI0B/M+AU/aA=
DN: 1.2.840.113549.1.9.1=#160e63726f73704078616b65702e7275,CN=195.xx.xx.xx,OU=Departament of Development,O=CROSP Solutions,L=Chernihiv,ST=Chernihiv,C=UA
subjectAltNames: []
at com.squareup.okhttp.internal.http.SocketConnector.connectTls(SocketConnector.java:124)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的主机名相同,但仍然存在错误.
请帮忙处理这个问题,我将不胜感激任何帮助.
谢谢.
伪解决方案
当然我之前搜索过并找到了HostName Verifier Solution.
我试过了,它有效.但是可以使用这种解决方法,我将证书添加到我的应用程序中,以便像在前面的示例中一样动态地读取它,它是否仍然在这种情况下使用.
OkHttp的解决方案是一行.(如果您按照教程中的所有步骤操作).
okHttpClient.setHostnameVerifier(new NullHostNameVerifier());
Run Code Online (Sandbox Code Playgroud)
但我还是觉得这不是最好的解决方案,请问有什么想法吗?
我想解决这个问题,
我在我的Android应用程序的build.gradle文件中声明了一些依赖项,但问题是很多这些依赖项使用相同的compat库,在我的情况下appcompat-v7.
可以为每个依赖项排除此库
compile ('com.github......'){
exclude group: 'com.android.support', module: 'appcompat-v7'
}
Run Code Online (Sandbox Code Playgroud)
但我需要为每个依赖项执行此操作.
另一种方法是使用此类表达式
configurations {
compile.exclude module: 'appcompat-v7'
}
Run Code Online (Sandbox Code Playgroud)
这可行,但即使明确声明此库,也会被忽略 compile 'com.android.support:appcompat-v7:+'
我需要的只是为整个应用程序只包含一次这个库,因为如果编译没有排除它会显示很多错误,如has been already defined.
也许有一种更简单的方法来实现这一点.我将非常感谢任何帮助,谢谢.
android gradle android-support-library android-studio android-gradle-plugin
我有两个服务应该通过Kafka. 让我们调用第一个服务WriteService和第二个服务QueryService。
在WriteService端,我对生产者有以下配置。
@Configuration
public class KafkaProducerConfiguration {
@Value("${spring.kafka.bootstrap-servers}")
private String bootstrapServers;
@Bean
public Map<String, Object> producerConfigs() {
Map<String, Object> props = new HashMap<>();
// list of host:port pairs used for establishing the initial connections to the Kakfa cluster
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
bootstrapServers);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
JsonSerializer.class);
return props;
}
@Bean
public ProducerFactory<String, Object> producerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfigs());
}
@Bean
public KafkaTemplate<String, Object> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试发送类的对象 com.example.project.web.routes.dto.RouteDto
在 …
spring apache-kafka json-deserialization spring-boot spring-kafka
我仍然试图让我的gradle脚本工作,我已经使用了所有日志,似乎有一些类缺失了.这是消息.
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':horizontalrecyclerview'.
Caused by: java.lang.NoClassDefFoundError: org/gradle/api/publication/maven/internal/DefaultMavenFactory
at org.gradle.api.plugins.AndroidMavenPlugin.apply(AndroidMavenPlugin.java:88)
at org.gradle.api.plugins.AndroidMavenPlugin.apply(AndroidMavenPlugin.java:57)
at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(Imper
Caused by: java.lang.ClassNotFoundException: org.gradle.api.publication.maven.internal.DefaultMavenFactory
... 51 more
Run Code Online (Sandbox Code Playgroud)
这是我的build.gradle.
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
version = "1.0.0"
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
def siteUrl = 'https://github.com/CROSP/AndroidHorizontalRecyclerView' // Homepage URL of the library
def …Run Code Online (Sandbox Code Playgroud) 我正在寻找从我的单独模块中导出所有常量的最有效和可读的方法,该模块仅用于存储常量.
例如
use strict;
use warnings;
use Readonly;
Readonly our $MY_CONSTANT1 => 'constant1';
Readonly our $MY_CONSTANT2 => 'constant2';
....
Readonly our $MY_CONSTANT20 => 'constant20';
Run Code Online (Sandbox Code Playgroud)
所以我有很多变量,并将它们全部列在我们的内部@EXPORT = qw( MY_CONSTANT1.... );
它会很痛苦.是否有任何优雅的方式导出所有常量,在我的情况下,Readonly变量(强制导出所有,不使用@EXPORT_OK).
我正在尝试构建我的库并将其上传到存储库,但不幸的是gradle构建失败.我花了几个小时试图修复这个错误,但我尝试的没有任何帮助.
这是我build.gradle的root项目目录.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1"
}
}
allprojects {
repositories {
jcenter()
}
}
Run Code Online (Sandbox Code Playgroud)
和我的模块目录中的build.gradle
apply plugin: 'com.android.library'
apply plugin: "com.jfrog.bintray"
apply plugin: 'com.github.dcendents.android-maven'
version = "1.0.0"
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
def siteUrl = 'https://github.com/CROSP/AndroidHorizontalRecyclerView' // Homepage URL of the library
def …Run Code Online (Sandbox Code Playgroud) 我正在使用Android-ObservableScrollView库.一切都很好,但我有活动来保存片段,所以所有视图都封装在片段中.在活动中,只有FrameLayout持有碎片.
所以我需要Toolbar在我的应用程序中使用,我有几个想法如何实现它.
在活动中使用工具栏,在这种情况下,我的布局将包含FrameLayout和Toolbar.通过这种方式,每当我需要对工具栏执行某些操作时,我都会与活动进行通信,我也可以通过使用getSupportedActionBar()片段来获取它.
在每个片段视图创建中使用工具栏内部片段(在其布局中)设置.每次我更改片段时,我都必须在活动中添加新的工具栏.在某些片段中,我将使用不同的工具栏但不是全部.是否在片段中存储工具栏是一种很好的方法.
我在使用第二种方法时可以看到的问题,如果屏幕上会有多个片段,那么还会有几个工具栏.
请在这种情况下建议正确的方法.
谢谢.
android toolbar android-fragments android-actionbar android-fragmentactivity
android ×6
gradle ×3
java ×3
angular ×1
apache-kafka ×1
constants ×1
css ×1
css3 ×1
dagger-2 ×1
git ×1
html ×1
https ×1
maven ×1
observable ×1
okhttp ×1
perl ×1
perl-module ×1
rxjs ×1
scope ×1
spring ×1
spring-boot ×1
spring-kafka ×1
ssl ×1
toolbar ×1
typescript ×1