有人能为我提供弹簧启动服务器端事件的示例吗?
基本上我需要将服务器端事件推送到浏览器.我正在使用角度2和弹簧启动后端.请提供一个示例示例,我无法找到好的示例.
@Controller
public class SSEController {
private final List<SseEmitter> emitters = new ArrayList<>();
@RequestMapping(path = "/stream", method = RequestMethod.GET)
public SseEmitter stream() throws IOException {
SseEmitter emitter = new SseEmitter();
emitters.add(emitter);
emitter.onCompletion(() -> emitters.remove(emitter));
return emitter;
}
}
Run Code Online (Sandbox Code Playgroud)
如何从服务器连续推送数据以及如何在Angular 2中订阅此事件?
提前致谢
angular2如何使用来自不同文件的ng-template?当我将ng-template放在我使用它的同一个HTML中时,但是当我将ng-template移动到一个单独的文件中时,它将无法工作.有没有办法将ng-template移动到自己的文件中并在不同的html文件中使用它?
INFO-message.html
<ng-template #messageTemplate>
Hi
</ng-template>
<ng-container *ngTemplateOutlet="messageTemplate;"></ng-container>
Run Code Online (Sandbox Code Playgroud)
以上工作正常,因为ng-template和用法在同一个文件中
消息template.html
<ng-template #messageTemplate>
Hi
</ng-template>
Run Code Online (Sandbox Code Playgroud)
INFO-message.html
<ng-container *ngTemplateOutlet="messageTemplate;"></ng-container>
Run Code Online (Sandbox Code Playgroud)
这不起作用.有没有办法使用"messageTemplate",它位于另一个html中的单独文件中(例如:info-message.html)
提前致谢.
HTML
<input type="checkbox" id="1" [(ngModel)]="filter" (change)="onFilterChange($event)"> CheckBox
<button (click)="filter = !filter">Change Status</button>
Run Code Online (Sandbox Code Playgroud)
TS
export class HelloWorld {
filter : false;
onFilterChange() {
console.log('filter change called');
}
}
Run Code Online (Sandbox Code Playgroud)
当我直接点击复选框时,会触发更改事件.但是当我点击"更改状态"按钮时,复选框状态正在改变,但更改事件未触发.有人可以让我知道怎么做吗?
有没有办法在不使用外部库的情况下检查JavaScript中的时区名称是否有效?
当用户在文本字段中输入时区名称时,我想验证区域是否有效?
我知道我们可以使用moment-timezone库轻松完成.但我不想使用任何额外的库.我正在寻找纯粹的JavaScript方式.
isValidTimeZone(name) {
//return true/false
}
isValidTimeZone('Asia/Colombo'); //returns true
isValidTimeZone('America/Los_Angeles'); //returns true
isValidTimeZone('MyTimeZone/ME'); //returns false
Run Code Online (Sandbox Code Playgroud) 在Splunk搜索查询中如何检查日志消息是否有文本?
日志消息:
message: 2018-09-21T07:15:28,458+0000 comp=hub-lora-ingestor-0 [vert.x-eventloop-thread-0] INFO com.nsc.iot.hono.receiver.HonoReceiver - Connected successfully, creating telemetry consumer ...
Run Code Online (Sandbox Code Playgroud)
我想检查消息是否包含“连接成功,创建遥测消费者...”并基于此想要将 1 或 0 分配给变量
Splunk 搜索查询
(index="05c48b55-c9aa-4743-aa4b-c0ec618691dd" ("Retry connecting in 1000ms ..." OR "Connect or create consumer failed with exception" OR "Connected successfully, creating telemetry consumer ..."))
| rex field=_raw ^(?:[^ \n]* ){7}(?P<success_status_message>\w+\s+\w+,\s+\w+\s+\w+\s+\w+)"
| timechart count as status | eval status=if(isnull(success_status_message), 0, 1)
Run Code Online (Sandbox Code Playgroud)
success_status_message 始终为 null
有人可以让我知道如何在做ngFor时切换图标吗?
问题陈述:我正在使用*ngFor循环遍历数组并显示类别名称.点击一天,我需要打开一个手风琴并显示类别详细信息(我可以这样做).一旦手风琴打开,我需要用fa-minus替换fa-plus图标,反之亦然,我只需要点击一天即可.
我怎样才能有效实现这一目标?
this.categoryList = [
{type: 'space', name: 'Space'},
{type: 'energy', name: 'Energy'},
{type: 'comfort', name: 'Comfort'},
{type: 'maintenance', name: 'Maintenance'},
{type: 'reporting', name: 'Reporting'}
];
Run Code Online (Sandbox Code Playgroud)
HTML
<div class="{{category.type}}" *ngFor="let category of categoryList">
<div data-toggle="collapse" [attr.href]="'#'+'category-'+category.type">
<div class="title {{category.name}}">{{category.name}}</div>
<div>
<i class="fa fa-plus"></i> //needs to toggle between plus and minus
<i class="fa fa-minus"></i> //needs to toggle between plus and minus
</div>
</div>
<div class="collapse" id="category-{{category.type}}">
//details
</div>
</div>
Run Code Online (Sandbox Code Playgroud) Cloud Foundry是否可以在执行蓝绿色部署时将丢失的路由从一个应用程序复制到另一个应用程序?
我有一个手动添加路线的应用程序,同时进行蓝绿色部署(通过脚本自动化)我想将丢失/手动添加的路由复制到新的应用程序.可能吗?
脚本:
#!/bin/bash
path="C:/Users/.../Desktop/cf_through_sh/appName.jar"
spaceName="development"
appBlue="appName"
appGreen="${appName}-dev"
manifestFile="C:/Users/.../Desktop/cf_through_sh/manifest-dev.yml"
domains=("domain1.com" "domain2.com")
appHosts=("host-v1" "host-v2")
evaluate_return_code (){
ret=$1
if [[ $ret != 0 ]]
then
exit $ret
fi
}
switch_to_target_space() {
space="development"
echo "Change space to ${space}"
cf t -s ${space}
evaluate_return_code $?
}
push_new_release() {
appGreen=$1
if [ ! -f "${manifestFile}" ]; then
echo "Missing manifest: ${manifestFile}";
exit 1;
fi
if [ ! -f "${path}" ]; then
echo "Missing artifact: ${path}";
exit 1;
fi
echo "Deploying ${path} as ${appGreen}"
cf …
Run Code Online (Sandbox Code Playgroud) 问题陈述:我的UI应用程序在9000端口(grunt项目)上运行,我的服务器端spring引导项目在8421端口上运行.除登录和注销外,我能够从我的UI应用程序中点击所有URL.请告诉我如何使用CORS配置spring security登录和注销.
App.js
$scope.login = function() {
$http.post('http://localhost:8421/login', $.param($scope.credentials), {
headers : {
'content-type' : 'application/x-www-form-urlencoded'
}
}).success(function() {
console.log('login success');
});
}).error(function() {
console.log('login error');
});
};
Run Code Online (Sandbox Code Playgroud)
SecurityConfiguration.java
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(new SimpleCORSFilter(), ChannelProcessingFilter.class)
.authorizeRequests().antMatchers("/rest/**").permitAll()
.and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/index.html")
.and().exceptionHandling().authenticationEntryPoint(authenticationEntryPoint)
.and().formLogin().successHandler(authenticationSuccessHandler)
.and().formLogin().failureHandler(authenticationFailureHandler)
.and().csrf().disable();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
}
}
Run Code Online (Sandbox Code Playgroud)
SimpleCORSFilter.java
public class SimpleCORSFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse …
Run Code Online (Sandbox Code Playgroud) 有人可以让我知道如何从android客户端连接到spring stomp Web套接字。
WebSocketConfig.java
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/pushticket");
config.setApplicationDestinationPrefixes("/rest");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ticket").withSockJS();
}
}
Run Code Online (Sandbox Code Playgroud)
PushMessageNotifier.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
@Service
@EnableAsync
public class PushMessageNotifier {
private SimpMessagingTemplate simpMessagingTemplate;
@Autowired
public PushMessageNotifier(SimpMessagingTemplate simpMessagingTemplate) {
this.simpMessagingTemplate = simpMessagingTemplate;
}
@Async
public Boolean pushToUI(TicketView ticketView) {
Boolean result = false;
if …
Run Code Online (Sandbox Code Playgroud) Angular2 Observable共享无效并且重复http调用
BuildingService.ts
@Injectable()
export class BuildingService {
constructor(private http: Http){
}
buildings$: Observable<Building[]>;
this.buildings: Building[];
getData() : Observable<Building[]>{
this.buildings$ = this.http.get('http://localhost:8080/buildings').share().map(this.extractData);
this.buildings$.subscribe(buildings => this.buildings = buildings);
return this.buildings$;
}
private extractData(res: Response) {
let body = res.json();
return body;
}
}
Run Code Online (Sandbox Code Playgroud)
component1.ts
export class component1 {
constructor( private buildingService: BuildingService) {}
this.subscription = this.buildingService.getData()
.subscribe(buildings => console.log(buildings),
error => this.errorMessage = <any>error);
}
Run Code Online (Sandbox Code Playgroud)
component2.ts
export class component2 {
constructor( private buildingService: BuildingService) {}
this.subscription = this.buildingService.getData()
.subscribe(buildings => console.log(buildings), …
Run Code Online (Sandbox Code Playgroud) angular ×5
java ×3
typescript ×3
spring-boot ×2
android ×1
angularjs ×1
bash ×1
checkbox ×1
cors ×1
devops ×1
events ×1
javascript ×1
loops ×1
ng-template ×1
ngfor ×1
observable ×1
rxjs ×1
rxjs5 ×1
shell ×1
splunk ×1
splunk-query ×1
spring-rest ×1
stomp ×1
timezone ×1
websocket ×1