分类 Java 下的文章

This is known issue in Hibernate, see https://hibernate.atlassian.net/browse/HHH-8805

Solution is to add @org.hibernate.annotations.ForeignKey(name = "none") on the mapped side.

class Parent {

  @OneToMany(mappedBy="parent", cascade=CascadeType.ALL, orphanRemoval=true)
  @OrderColumn(name="childIndex")
  @org.hibernate.annotations.ForeignKey(name = "none")
  public List<Child> getChildren() {
    return children;
  }

}

Note: Prefer the JPA 2.1 introduced javax.persistence.ForeignKey instead. The native annotation is deprecated.

answerd by Bustanil Arifin and sophros How do I disable Hibernate foreign key constraint on a bidirectional association?

Here is the difference:

  • addFlashAttribute() actually stores the attributes in a flashmap (which is internally maintained in the users session and removed once the next redirected request gets fulfilled)
  • addAttribute() essentially constructs request parameters out of your attributes and redirects to the desired page with the request parameters.

So the advantage of addFlashAttribute() will be that you can store pretty much any object in your flash attribute (as it is not serialized into request params at all, but maintained as an object), whereas with addAttribute() since the object that you add gets transformed to a normal request param, you are pretty limited to the object types like String or primitives.

answerd by Biju Kunjummen https://stackoverflow.com/questions/14470111/spring-redirectattributes-addattribute-vs-addflashattribute

denis-anisimov:

This looks like a bug in Spring: spring-projects/spring-boot#27147

JS WebSocket class can't connect to the server and there is nothing to fix on our side.
The same happens with:

  • console code ws = new WebSocket("ws://localhost: 35729");
  • Live reload Chrome extension: it doesn't work with 2.5.2

pleku:
Fixed in Spring Boot 2.4.9 & 2.5.3

Live reload is broken starting with Spring Boot 2.5.2 #11375
DevTools' LiveReload support's HTTP header handling is case sensitive #26813

    <mvc:annotation-driven/>
...
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" />
                </bean>
                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
            </list>
        </property>
    </bean>

此时配置,response content-type 依然是 text/plain;charset=ISO-8859-1

    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <constructor-arg>
                    <util:constant static-field="java.nio.charset.StandardCharsets.UTF_8"/>
                </constructor-arg>
                <property name="writeAcceptCharset" value="false" />
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

<mvc:annotation-driven> 配置存在时,bean StringHttpMessageConverter 放于 <mvc:message-converters> 中, response 才能正确返回 text/plain;charset=UTF-8


声明 util:
<beans ...
     xmlns:util="http://www.springframework.org/schema/util"
...
 xsi:schemaLocation="...
     http://www.springframework.org/schema/util
     http://www.springframework.org/schema/util/spring-util-3.1.xsd
...">
xml: 注入静态成员变量至 spring bean
https://www.cnblogs.com/yzx2018/p/8884141.html

Since there are several answers here showing non-working code for Windows, here is a clarification:

Runtime.getRuntime().exec("cls");

This command does not work, for two reasons:

There is no executable named cls.exe or cls.com in a standard Windows installation that could be invoked via Runtime.exec, as the well-known command cls is builtin to Windows’ command line interpreter.

When launching a new process via Runtime.exec, the standard output gets redirected to a pipe which the initiating Java process can read. But when the output of the cls command gets redirected, it doesn’t clear the console.

To solve this problem, we have to invoke the command line interpreter (cmd) and tell it to execute a command (/c cls) which allows invoking builtin commands. Further we have to directly connect its output channel to the Java process’ output channel, which works starting with Java 7, using inheritIO():

import java.io.IOException;

public class CLS {
    public static void main(String... arg) throws IOException, InterruptedException {
        new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
    }
}

Now when the Java process is connected to a console, i.e. has been started from a command line without output redirection, it will clear the console.

https://stackoverflow.com/questions/2979383/how-to-clear-the-console