我错过了什么?为什么我必须在Object::toString下面使用而不是Integer::toString?它与带有泛型的类型擦除有什么关系吗?
Arrays.asList(1,2,3).stream().map(Integer::toString).forEach(System.out::println); //Won't compile
Arrays.asList(1,2,3).stream().map(Object::toString).forEach(System.out::println); //Compiles and runs fine
Run Code Online (Sandbox Code Playgroud) 我还在学习Go.我试图将json解组成一个struct.但是,struct有一个带标记的字段.使用反射,我试着看看标签中是否有字符串"json".如果确实如此,那么json to unmarshal应该简单地作为字符串解组到字段中.
例:
const data = `{"I":3, "S":{"phone": {"sales": "2223334444"}}}`
type A struct {
I int64
S string `sql:"type:json"`
}
Run Code Online (Sandbox Code Playgroud)
问题很简单 - 将json中的"S"解组为结构A中的字符串.
这就是我走了多远.但我被困在这里.
不知道这意味着什么,但我在kotlin html代码库中遇到了这种语法.SCRIPT.()是什么意思?
fun FlowOrPhrasingOrMetaDataContent.script(type : String? = null, src : String? = null, block : SCRIPT.() -> Unit = {}) : Unit = SCRIPT(attributesMapOf("type", type,"src", src), consumer).visit(block)
Run Code Online (Sandbox Code Playgroud)
SCRIPT是一个类 - https://github.com/Kotlin/kotlinx.html/blob/master/shared/src/main/kotlin/generated/gen-tags-s.kt.
或者更一般地说,<ClassName>.()Kotlin的意思是什么?
为什么这种AES加密不起作用?我用Java编写它来测试,但我无法解密.解密后我得到了垃圾.为什么?它如此简单 - 在主要方法中,打印纯文本,加密,打印密文,解密,再次打印纯文本.难道我做错了什么?请帮我弄清楚问题所在.
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class AESTest {
public static void main(String [] args) {
try {
String plainText = "Hello World!!!!!";
String encryptionKey = "E072EDF9534053A0B6C581C58FBF25CC";
System.out.println("Before encryption - " + plainText);
String cipherText = encrypt(plainText, encryptionKey);
System.out.println("After encryption - " + cipherText);
String decrypted = decrypt(cipherText, encryptionKey);
System.out.println("After decryption - " + decrypted);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String encrypt(String plainText, String passkey) throws Exception {
Cipher cipher = …Run Code Online (Sandbox Code Playgroud) 如果我有一个文件名是
a'd1 & "[tttt]" + 'sq.jpg
将其上传到Amazon S3后,它将转换为
a'd1 & %22[tttt]%22 + 'sq.jpg
因此,双引号是URL编码的,文件名本身也已更改。
必须使用编码的URL提取文件
a%27d1+%26+%2522%5Btttt%5D%2522+%2B+%27sq.jpg
因此编码规则似乎是:
": %2522 (double encoded)
Space: +
&: %26
[: %5B
]: %5D
+: %2B
Run Code Online (Sandbox Code Playgroud)
有没有办法确定S3要求的所有规则?使用(encodeURI甚至encodeURIComponent)的普通javascript编码将无法正常工作
我有两个项目.一个Maven和一个Gradle.该公司还有一个内部maven存储库.我正在尝试设置Gradle以使用内部仓库.使用Intellij 13时,我将这样的repo添加到build.gradle中的Gradle
build.gradle文件:
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.5
version = '1.0'
maven {
url "http://nexus.company.com/nexus/repo"
}
mavenLocal()
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
Run Code Online (Sandbox Code Playgroud)
.m2/settings.xml似乎被gradle完全忽略(我尝试不将maven repo添加到build.gradle文件中,并希望gradle将查看.m2/settings.xml以确定从哪里获取工件)
.m2/settings.xml文件
<settings>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://nexus.company.com/nexus/repo</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>central-repo</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>central-repo</activeProfile>
</activeProfiles>
</settings>
Run Code Online (Sandbox Code Playgroud)
当repo为http://nexus.company.com/nexus/repo时,Intellij会在后台任务中永远旋转,说"处理索引" .没有它,一切工作都很好,除了内部工件无法下载.
但是,maven项目需要相同的工件下载并在几秒钟内就绪.
我很陌生.我犯了什么错吗?
不知道出了什么问题,但AOP似乎没有在弹簧启动(v1.1.6)的设置中工作.
@Configuration
@ComponentScan
@EnableJpaRepositories
@EnableTransactionManagement
@EnableAutoConfiguration
@EnableCaching
@EnableLoadTimeWeaving
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
而在方面类
@Aspect
public class MyAspect {
@AfterReturning(pointcut = "execution(private * com.myapp.service.MyService.test(..)) && args(str1,str2)", argNames = "str1,str2")
public void advice(String str1, String str2) throws IOException {
System.out.println("Advising after returning");
}
}
Run Code Online (Sandbox Code Playgroud)
在需要建议的服务类中
@Service
public class MyService {
public void test(String str1, String str2) throws IOException {
System.out.println("Test method in service");
//rest of the implementation
}
}
Run Code Online (Sandbox Code Playgroud)
我也有像这样的META-INF/aop.xml
<!DOCTYPE aspectj …Run Code Online (Sandbox Code Playgroud) 谁能告诉我为什么在使用弹簧靴时不会触发方面?我正在尝试使用 aspectj 设置加载时间编织,以便我可以建议私有方法。
这是准系统项目的链接 - https://github.com/satb/spring_aop_test_project.git
使用“-javaagent:path/to/spring-instrument-4.1.0.RELEASE.jar”(或计算机上其他版本的lib)运行“App”类并运行curl命令
curl -i http://localhost:8080/test-app/motd
Run Code Online (Sandbox Code Playgroud)
MyAspect 类有一个建议,应该在调用 MyService 的私有方法时执行。但在这种情况下,什么也不会发生。
但是,当应用程序启动时,我看到如下消息:
[AppClassLoader@58644d46] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified.
Run Code Online (Sandbox Code Playgroud)
我尝试按照这里的建议让它工作,但这没有帮助 -将 @Autowired 与 AspectJ 和 Springboot 一起使用
我们有一个Spring Boot应用程序,由于集成需求,该应用程序的复杂性不断增加-例如在执行此操作后发送电子邮件,或在此之后广播jms消息等。在寻找更高层次的抽象时,我遇到了apache camel(haven)从未使用过骆驼)。我的问题是如何使用Spring Boot应用程序?该应用程序具有标准的spring控制器,服务,并使用spring-data来连接数据库。我没有在网上找到关于如何将骆驼合并到Spring-boot Restful应用程序中的任何帮助。难道这甚至是可行的事情,或者骆驼是完全不适合弹簧靴的野兽吗?
我确实读过Camel与Spring紧密集成,但是我仍然不知道1)Spring Controllers仍然可以与Camel一起使用2)如果我可以从骆驼路线中调用其他spring bean,以及是否可以调用从春豆调用骆驼路线(对不起,如果这听起来像是专家的骆驼新手问题,抱歉)
作为我们必须做的事的一个例子:
今天,每个http请求都通过Spring MVC堆栈传入。
在完成特定任务后,是否有办法将处理过程“转交给”骆驼?(例如,通过Spring MVC堆栈成功将订单写入数据库,然后交给骆驼发送jms消息并执行其他操作)?还是应该用Camel完全替代Spring?
不确定正确的路径是什么。有人可以指导我们吗?
如果它无效,那怎么会不呈现null sql.NullString呢?- http://play.golang.org/p/pzSWS9vE0J
它似乎没有使用omitempty struct标签,我无法弄清楚从MarshalJSON返回什么,以便omitempty将被尊重
type NS struct {
sql.NullString
}
func (ns *NS) MarshalJSON() ([]byte, error) {
fmt.Println("Marshaling json for NS")
if ns.String == "" && !ns.Valid {
return []byte("null"), nil
}
return json.Marshal(ns.String)
}
type A struct {
RStr string `json:rstr,omitempty"`
Str NS `json:"str,omitempty"`
}
func main() {
a := A{RStr: "rstr"}
s, _ := json.Marshal(&a)
fmt.Println(string(s))
}
Run Code Online (Sandbox Code Playgroud) spring ×3
spring-boot ×3
go ×2
java ×2
aes ×1
amazon-s3 ×1
aop ×1
apache-camel ×1
aspectj ×1
build.gradle ×1
encryption ×1
gradle ×1
java-8 ×1
json ×1
kotlin ×1
maven ×1
maven-3 ×1
spring-aop ×1
spring-mvc ×1
url-encoding ×1