我用spring-data-jpa用spring-boot(v2.0.0.RELEASE),只是写在MySQL凝乳演示,但它如下发生运行时异常,源代码如下:
源代码
User.java
@Entity
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Integer id;
private String username;
private String password;
...getter&setter
}
Run Code Online (Sandbox Code Playgroud)
UserRepository.java
public interface UserRepository extends JpaRepository<User, Integer> {
}
Run Code Online (Sandbox Code Playgroud)
UserServiceTest.java
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserServiceTest {
@Autowired
private UserRepository userRepository;
@Test
public void getUserById() throws Exception{
userRepository.getOne(1);
}
}
Run Code Online (Sandbox Code Playgroud)
application.yml
spring:
datasource:
username: ***
password: ***
driver-class-name: com.mysql.jdbc.Driver
url: ********
thymeleaf:
cache: false
jpa:
show-sql: true
hibernate: …Run Code Online (Sandbox Code Playgroud) 我将通道缓冲区的大小设置为零,例如var intChannelZero = make(chan int),从中获取值时intChannelZero将被阻塞,直到intChannelZero具有值为止。
另外,var intChannelOne = make(chan int, 1)当从中获取值时,将通道缓冲区的大小设置为1,例如,intChannelOne将被阻塞,直到intChannelOne具有值为止。
我们知道容量intChannelZero为零,容量intChannelOne为一,所以我想知道:
intChannelZerolike时intChannelZero <- 1,将值保存在哪里? intChannelZero以及intChannelOne何时赋予它们价值。谁可以在Golang运行时环境级别解释它?非常感谢。
我用Spring WebFlux写了一个Rest Controller Demo,无法正常运行,源码如下:
@RestController
public class Demo{
@PostMapping(value = "test2")
public Integer getHashCode(@RequestParam("parameters") String parameters){
return parameters.hashCode();
}
}
Run Code Online (Sandbox Code Playgroud)
我用 Postman 测试了一下,返回:
{
"timestamp": "2018-05-07T07:19:05.303+0000",
"path": "/test2",
"status": 400,
"error": "Bad Request",
"message": "Required String parameter 'parameters' is not present"
}
Run Code Online (Sandbox Code Playgroud)
依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> …Run Code Online (Sandbox Code Playgroud) 看下面两个代码片段:
code1:
func getIntJ1() (j int32) {
for {
j = 20
return
}
}
Run Code Online (Sandbox Code Playgroud)
码2:
func getIntJ2() (j int32) {
for true {
j = 20
return
}
}
Run Code Online (Sandbox Code Playgroud)
游乐场:https://play.golang.org/p/ZnwjZDksZhu
我认为他们应该20在控制台中打印相同的值,但他们不能做我想要的.
在code1可以打印值20在控制台中,但code2会出现编译错误:missing return at end of function.
所有这些都有infinite loop功能,为什么它们显示不同的结果?