我正在尝试使用Spring Boot做一个简单的测试。
mockMvc.perform(post("/user")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(userJohn)))
.andExpect(jsonPath("$[0].username", is("bob")));
Run Code Online (Sandbox Code Playgroud)
将此导入用于jsonPath:
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Run Code Online (Sandbox Code Playgroud)
我得到:
andExpect (org.springframework.test.web.servlet.ResultMatcher) in ResultActions cannot be applied to (org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath)
Run Code Online (Sandbox Code Playgroud)
如果我尝试将其强制转换为(ResultMatcher),则会得到:
java.lang.ClassCastException: org.springframework.test.web.servlet.result.JsonPathResultMatchers cannot be cast to org.springframework.test.web.servlet.ResultMatcher
Run Code Online (Sandbox Code Playgroud)
我正在使用Spring Boot的2.0.4版本。有什么问题的想法吗?
谢谢
大家好,我的程序中的每个人都收到了这样的日期:2015-01-18
这是一个日历对象,我需要从对象中获取日、月和年。现在我做这样的事情:
int day = date.get(Calendar.DAY_OF_MONTH);
int month = date.get(Calender.MONTH + 1);
int year = date.get(Calender.Year);
Run Code Online (Sandbox Code Playgroud)
输出是:
day = 18
month = 1
year = 2015
Run Code Online (Sandbox Code Playgroud)
我的问题是,我想在这种情况下获得月份,例如 01 而不是 1,因为该值稍后会在我的代码中解析并且需要采用该格式。在 1 之前附加 0 是丑陋的,所以任何人都知道输入代码这里有更好的方法来做到这一点?谢谢
嗨,我想生成2个值之间的随机数.我有2个变量.这是默认值:(MIN = MAX = 1)
以后这个值可以改变!
我用过这个:
rand()%(max-min)+min;
Run Code Online (Sandbox Code Playgroud)
但是我得到了关于除零的调试.有任何想法吗?
编辑:使用默认值生成的数字必须为1.