使用反射以及http://docs.oracle.com提供的安装程序中安装的JDK中提供的src.zip ,我找到了以下字段java.lang.System,
in, out&err被宣布为final,但他们有各自的(公共)setter方法,这些方法反过来调用他们各自的本地部分.
例如,我可以成功地将控制台输出重定向到文件.
我们可以在Java代码中初始化后准确设置最终变量.
我的问题是:这个最终规则不适用于本机代码吗?
我需要将 String(这是一个有效的整数)与 int 值进行比较。
对于String str, int integer,我的选择是:
Integer.parseInt(str) == integer
str.equals(Integer.toString(integer))
哪一种更快,有没有更好的方法?
以下受到 atlaste 答案的 EqualsIntString 的启发
private static boolean checkEquality(final String string, final long value) {
if (string == null) {
return false;
}
final int length = string.length();
if (length == 0) {
return false;
}
long absValue;
final byte minIndex;
if (string.charAt(0) == '-') {
if (value > 0) {
return false;
}
absValue = -value;
minIndex = 1;
} else {
if …Run Code Online (Sandbox Code Playgroud) 使用Spring Boot(v1.2.6.RELEASE),我需要接受对Controller方法的POST请求.
@RestController
@RequestMapping(value = "/myWebApp/signup")
public class RegController {
@RequestMapping(value = "/registerFamily", method = { RequestMethod.POST }, headers = {"Content-type=application/json"})
@ResponseBody
public FamilylResponse registerFamily(@RequestBody @Valid FamilyRequest familyRequest){
Run Code Online (Sandbox Code Playgroud)
...}
当我从Chrome/mozilla的REST客户端发送POST请求时,响应如下:
{"timestamp":1446008095543,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/myWebApp/signup/registerFamily"}
...
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪如下:
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
at org.springframework.web.servlet.support.WebContentGenerator.checkAndPrepare(WebContentGenerator.java:273)
at org.springframework.web.servlet.support.WebContentGenerator.checkAndPrepare(WebContentGenerator.java:251)
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:207)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
Run Code Online (Sandbox Code Playgroud)
在Spring的响应之后:不接受mvc:resources下的POST请求?如何解决这个问题,
我认为WebContentGenerator的其他一些子类,如WebContentInterceptor,RequestMappingHandlerAdapter 应该处理对控制器的请求.
此外,在运行Junit测试时,我发现RequestMappingHandlerAdapter正在处理对控制器的这些请求.
但是我还没有找到如何配置它来接受POST请求呢?
任何其他更好的解决方案都应该受到欢迎.
编辑:
Tomcat …
public interface ItemRepository extends JpaRepository<Item, Integer> {
List<Item> findByNameAndDescriptionIsNullOrDescription(String name, String desc);
}
Run Code Online (Sandbox Code Playgroud)
在本机Query中,where条件findByNameAndDescriptionIsNullOrDescription被转换为
where item0_.NAME=? and (item0_.DESC is null) or item0_.DESC=?
Run Code Online (Sandbox Code Playgroud)
我需要 where item0_.NAME=? and (item0_.DESC is null or item0_.DESC=?)
我使用以下内容
弹簧数据公地1.6.3.RELEASE.jar
弹簧数据JPA-1.4.3.RELEASE.jar
(i)hibernate-entitymanager-4.2.14.SP1-redhat-1.jar,(ii)hibernate-jpa-2.0-api-1.0.1.Final-redhat-2.jar由JBOSS EAP 6.3提供