Spring 5为webflux引入了rest API的反应式编程风格.我自己也很陌生,并且想知道将数据库的同步调用包装成有意义Flux还是Mono有意义?如果是,这是这样做的方式:
@RestController
public class HomeController {
private MeasurementRepository repository;
public HomeController(MeasurementRepository repository){
this.repository = repository;
}
@GetMapping(value = "/v1/measurements")
public Flux<Measurement> getMeasurements() {
return Flux.fromIterable(repository.findByFromDateGreaterThanEqual(new Date(1486980000L)));
}
}
Run Code Online (Sandbox Code Playgroud)
是否有类似异步CrudRepository的东西?我找不到它.
有人可以解释为什么这不会在R中单独打印所有数字
numberstring <- "0123456789"
for (number in numberstring) {
print(number)
}
Run Code Online (Sandbox Code Playgroud)
字符串不是字符数组吗?什么方式在R中做到这一点?
我收到消息Expression type DslEntry must conform to Def.SettingsDefinition in SBT file,enablePlugins(JavaServerAppPackaging)我尝试刷新项目,但它没有帮助.整个sbt文件主要由lightbend(以前的类型安全)激活器生成,如下所示
import NativePackagerHelper._
name := """ping-backend"""
version := "2.4.0"
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.4.0",
"com.typesafe.play" %% "play-json" % "2.4.6",
"org.igniterealtime.smack" % "smack-java7" % "4.1.0",
"org.igniterealtime.smack" % "smack-tcp" % "4.1.0",
"org.igniterealtime.smack" % "smack-im" % "4.1.0",
"org.igniterealtime.smack" % "smack-extensions" % "4.1.0"
)
enablePlugins(JavaServerAppPackaging)
mainClass in Compile := Some("sample.hello.Main")
mappings in Universal ++= {
// optional example illustrating how to copy additional directory
directory("scripts") …Run Code Online (Sandbox Code Playgroud) 通常,dart文档在几乎任何主题上都有很多有用的示例.不幸的是我在飞镖的会话中找不到任何东西.
任何人都可以将此方法验证为正确的会话方式:
我特别感兴趣的是第4,5和6点,因为其他的都有很好的记录.如果您可以在这一点上分享一些代码片段,我将非常感激.
编辑:在阅读GünterZöchbauer的评论后,我查看了shelf_auth.我意识到它需要重写服务器应用程序以使用货架.所以我做到了.
main.dart:
// imports of all necessary libraries
main() {
runServer();
}
/**
* Code to handle Http Requests
*/
runServer() {
var staticHandler = createStaticHandler(r"C:\Users\Lukasz\dart\auctionProject\web", defaultDocument: 'auctionproject.html');
var handler = new Cascade()
.add(staticHandler) // serves web-client
.add(routes.handler) // serves content requested by web-client
.handler;
io.serve(handler, InternetAddress.LOOPBACK_IP_V4, 8080).then((server) {
print('Listening on port 8080');
}).catchError((error) => print(error));
}
Run Code Online (Sandbox Code Playgroud)
routes.dart
import 'handlers.dart' as handler;
import 'package:shelf_route/shelf_route.dart';
import 'package:shelf_auth/shelf_auth.dart' as sAuth;
Router routes = …Run Code Online (Sandbox Code Playgroud) 我正在跟随Scala中关于函数式编程的Coursera课程,并且出现了工作表repl的奇怪行为.
在本课程中,带有以下代码的工作表应在右侧给出以下结果:
object rationals {
val x = new Rational(1, 2) > x : Rational = Rational@<hash_code>
x.numer > res0: Int = 1
y. denom > res1: Int = 2
}
class Rational(x: Int, y: Int) {
def numer = x
def denom = y
}
Run Code Online (Sandbox Code Playgroud)
我得到的是
object rationals { > defined module rationals
val x = new Rational(1, 2)
x.numer
y. denom
}
class Rational(x: Int, y: Int) { > defined class Rational
def numer = x
def denom …Run Code Online (Sandbox Code Playgroud) 我想通过从scala工作表运行它来测试一个类.运行此测试脚本时:
import ping.GcmRestServer
val server = new GcmRestServer("AIzaSyCOn...")
server.send(List("dcGKzDg5VOQ:APA91bHNUDaBj01th..."), Map(
"message" -> "Test Message",
"title" -> "Test Title"
))
Run Code Online (Sandbox Code Playgroud)
是测试类GcmRestServer是
package ping
import play.api.Logger
import play.api.libs.ws.WS
import play.api.libs.json.Json
/**
* Created by Lukasz on 26.02.2016.
*/
class GcmRestServer(val key: String) {
def send(ids: List[String], data: Map[String, String]) = {
import play.api.Play.current
import scala.concurrent.ExecutionContext.Implicits.global
val body = Json.obj(
"registration_ids" -> ids,
"data" -> data
)
WS.url("https://android.googleapis.com/gcm/send")
.withHeaders(
"Authorization" -> s"key=$key",
"Content-type" -> "application/json"
)
.post(body)
.map { response => Logger.debug("Result: " …Run Code Online (Sandbox Code Playgroud) 通过套接字发送一组int有麻烦.代码看起来像这样
程序1(在Windows上运行)
int bmp_info_buff[3];
/* connecting and others */
/* Send informations about bitmap */
send(my_socket, (char*)bmp_info_buff, 3, 0);
Run Code Online (Sandbox Code Playgroud)
计划2(在中微子上运行)
/*buff to store bitmap information size, with, length */
int bmp_info_buff[3];
/* stuff */
/* Read informations about bitmap */
recv(my_connection, bmp_info_buff, 3, NULL);
printf("Size of bitmap: %d\nwidth: %d\nheight: %d\n", bmp_info_buff[0], bmp_info_buff[1], bmp_info_buff[2]);
Run Code Online (Sandbox Code Playgroud)
它应该打印位图的大小:64
宽度:8
高度:8
位图大小:64
宽度:6
高度:4096
我做错了什么?
我的布局遇到了一些问题我无法解释.
布局HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AuctionProject</title>
<script async type="application/dart" src="auctionproject.dart"></script>
<script async src="packages/browser/dart.js"></script>
<link rel="stylesheet" href="auctionproject.css">
</head>
<body>
<div id="menu_bar">
<div id="logo"></div>
<div class="menu_tab" id="123">Tab123</div>
<div class="menu_tab" id="upcomming">Tab456</div>
</div>
<div id="content_box">
<div id="side_menu">
<div id="open_menu_shadow"></div>
<div id="menu_content" class="hidden">
<div id="account" class="side_label hidden">
<p class="tiny">You are currently logged in as:</p>
<p id="current_user">Some User</p>
<p class="tiny">This is not you?
<span class="important" id="log_out" role="button" tabindex="0" style="cursor: pointer;">Log Out</span>
</p>
</div>
<div id="login_box" class="side_label">
<input type="text" name="login" …Run Code Online (Sandbox Code Playgroud) 在我的一个项目中,我有一个 akka 演员,用于向我的 google fcm 服务器发送帖子请求。演员接受一个 id 列表,并且应该发出与列表中一样多的请求。我打印出来自服务器的响应,runForeach(println(_))但我只得到一个完整的 id 列表的打印输出。为什么会发生这种情况?
class FCMActor(val key: String) extends Actor{
import fcm.FCMActor._
import akka.pattern.pipe
import context.dispatcher
private implicit def system: ActorSystem = ActorSystem()
final implicit val materializer: ActorMaterializer = ActorMaterializer(ActorMaterializerSettings(context.system))
def buildBody(id: Option[String]): String = {
Json.obj(
"to" -> id,
"priority" -> "high",
"data" -> Json.obj("message" -> "Firebase Clud Message"),
"time_to_live" -> 60
).toString()
}
def buildHttpRequest(body: String): HttpRequest = {
HttpRequest(method = HttpMethods.POST,
uri = s"/fcm/send",
entity = HttpEntity(MediaTypes.`application/json`, body),
headers …Run Code Online (Sandbox Code Playgroud) 这个问题与这篇文章相关。
我尝试了以下代码:
import 'dart:convert';
/*server side Post class */
class Post {
int post_id;
String title;
String description;
DateTime posted_at;
DateTime last_edited;
String user;
String editor;
int up_votes;
int down_votes;
int total_votes;
String links_to;
List<String> tags = new List();
Post.fromSQL(List sql_post) {
//initialization code, unrelated.
}
Map toJson(){
Map fromObject = {
'post_id' : post_id,
'title' : title,
'description' : description,
'posted_at' : posted_at,
'last_edited' : last_edited,
'user' : user,
'editor' : editor,
'up_votes' : up_votes,
'dwon_votes' : down_votes, …Run Code Online (Sandbox Code Playgroud)