分类 Code 下的文章

There is a way using CSS!

If you set your width depending on the parent container you can set the height to 0 and set padding-bottom to the percentage which will be calculated depending on the current width:

.some_element {
    position: relative;
    width: 20%;
    height: 0;
    padding-bottom: 20%;
}

This works well in all major browsers.

https://stackoverflow.com/questions/5445491/height-equal-to-dynamic-width-css-fluid-layout

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

git 设置用户名邮箱:

对当前项目生效:

git config user.name 'your username'
git config user.email 'your email'

对全局生效,加上 --global:

git config --global user.name 'your username'
git config --global user.email 'your email'

As an answer to okutane, please see snippet:

@JoinColumn(name = "car_id", insertable = false, updatable = false)
@ManyToOne(targetEntity = Car.class, fetch = FetchType.EAGER)
private Car car;

@Column(name = "car_id")
private Long carId;

So what happens here is that when you want to do an insert/update, you only populate the carId field and perform the insert/update. Since the car field is non-insertable and non-updatable Hibernate will not complain about this and since in your database model you would only populate your car_id as a foreign key anyway this is enough at this point (and your foreign key relationship on the database will ensure your data integrity). Now when you fetch your entity the car field will be populated by Hibernate giving you the flexibility where only your parent gets fetched when it needs to.

answered by 'Jonck van der Kogel'

JPA many-to-one relation - need to save only Id

Java TypeJava DB, Derby, CloudScapeOracleDB2SybaseMS-SQL ServerMySQL Server
boolean, java.lang.BooleanSMALLINTNUMBER(1)SMALLINTBITBITTINYINT(1)
int, java.lang.IntegerINTEGERNUMBER(10)INTEGERINTEGERINTEGERINTEGER
long, java.lang.LongBIGINTNUMBER(19)INTEGERNUMERIC(19)NUMERIC(19)BIGINT
float, java.lang.FloatFLOATNUMBER(19,4)FLOATFLOAT(16)FLOAT(16)FLOAT
double, java.lang.DoubleFLOATNUMBER(19,4)FLOATFLOAT(32)FLOAT(32)DOUBLE
short, java.lang.ShortSMALLINTNUMBER(5)SMALLINTSMALLINTSMALLINTSMALLINT
byte, java.lang.ByteSMALLINTNUMBER(3)SMALLINTSMALLINTSMALLINTSMALLINT
java.lang.NumberDECIMALNUMBER(38)DECIMAL(15)NUMERIC(38)NUMERIC(28)DECIMAL(38)
java.math.BigIntegerBIGINTNUMBER(38)BIGINTNUMERIC(38)NUMERIC(28)BIGINT
java.math.BigDecimalDECIMALNUMBER(38)DECIMAL(15)NUMERIC(38)NUMERIC(28)DECIMAL(38)
java.lang.StringVARCHAR(255)VARCHAR(255)VARCHAR(255)VARCHAR(255)VARCHAR(255)VARCHAR(255)
char, java.lang.CharacterCHAR(1)CHAR(1)CHAR(1)CHAR(1)CHAR(1)CHAR(1)
byte[], java.lang.Byte[], java.sql.BlobBLOB(64000)LONG RAWBLOB(64000)IMAGEIMAGEBLOB(64000)
char[], java.lang.Character[], java.sql.ClobCLOB(64000)LONGCLOB(64000)TEXTTEXTTEXT(64000)
java.sql.DateDATEDATEDATEDATETIMEDATETIMEDATE
java.sql.TimeTIMEDATETIMEDATETIMEDATETIMETIME
java.sql.TimestampTIMESTAMPDATETIMESTAMPDATETIMEDATETIMEDATETIME
Supported Data Types (Sun Java System Application Server Platform Edition 9 Developer's Guide)