我最近被聘为初级 Java 开发人员,我们正在使用 Spring 框架。我真的很喜欢它,但问题是:当涉及到一些我还不理解的 Spring 功能时,我仍然感到不舒服。我打算在空闲时间深入学习Spring。不幸的是我没有使用Java EE的经验(实际上我对JavaEE几乎一无所知。我的JEE知识都是理论知识)...所以我的问题是:如果我将来想继续使用Spring,是否必须学习JEE?谢谢。
我正在使用Spring Boot和PostgreSQL数据库。我有这个实体类:
@Entity
@Table(name = "TEST")
public class Test {
@Id
@GeneratedValue
private Long id;
}
Run Code Online (Sandbox Code Playgroud)
这是我的application.properties文件:
spring.datasource.url = jdbc:postgresql://localhost:5432/postgres
spring.datasource.username = postgres
spring.datasource.password = 1234
spring.jpa.hibernate.ddl-auto= update
spring.jpa.properties.hibernate.dialect =
org.hibernate.dialect.PostgreSQL94Dialect
Run Code Online (Sandbox Code Playgroud)
它创建表,但表的名称是test(小写)。怎么改成大写呢?
这是我的pom.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.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> …Run Code Online (Sandbox Code Playgroud) 我正在看书Spring In Action,有一个例子:
public BlankDisc(@Value("#{systemProperties['disc.title']}" String title){
}
Run Code Online (Sandbox Code Playgroud)
但是systemProperties这里是什么以及在哪里声明它?我认为它是application.properties文件并添加到disc.title=Beatles那里。但是title变量的值是null在创建 bean 时。顺便说一下,我可以注入disc.titleif 我使用的值@Value("${disc.title}")。
我有一个从字符串中检索第一个单词的函数:
\n\nCREATE FUNCTION dbo.FIRST_WORD(@value nvarchar(1000))\nRETURNS nvarchar(1000)\nAS\nBEGIN\nRETURN CASE CHARINDEX(' ', @value, 1)\n WHEN 0\n THEN @value\n ELSE SUBSTRING(@value, 1, CHARINDEX(' ', @value, 1) - 1) END\n END\nGO \nRun Code Online (Sandbox Code Playgroud)\n\n问题是我的表中的数据是格式化的non-ASCII,所以当我将一些值传递给该函数时,我得到问号而不是结果:
SELECT dbo.FIRST_WORD('\xd0\xbd\xd0\xb8\xd1\x87\xd0\xb5\xd0\xb3\xd0\xbe \xd0\xbd\xd0\xb5 \xd0\xbf\xd0\xbe\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0\xd0\xb5\xd1\x88\xd1\x8c')
返回:??????
但是如果我传递ASCII字符,例如:
SELECT dbo.FIRST_WORD('hello world')
它返回:hello正如预期的那样。
我尝试在参数之前添加N,但没有帮助:
SELECT dbo.FIRST_WORD(N'\xd0\xbd\xd0\xb8\xd1\x87\xd0\xb5\xd0\xb3\xd0\xbe \xd0\xbd\xd0\xb5 \xd0\xbf\xd0\xbe\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0\xd0\xb5\xd1\x88\xd1\x8c')
仍然返回:??????
我有一个界面:
interface Change
Run Code Online (Sandbox Code Playgroud)
和一个功能:
fun test (listOfChanges: List<Change>)
Run Code Online (Sandbox Code Playgroud)
和实现Change接口的此类:
class MyChange :Change
Run Code Online (Sandbox Code Playgroud)
如何检查是否listOfChanges有MyChange类元素?
喜欢: if(listOfchanges.contains(MyChange::class)
谁能给我一个理由,为什么new Exception()在这里被忽略?
void bar() throws IOException { //no Exception declared, compilator is ok about that. Why?
try{
throw new EOFException();
}
catch(EOFException eofe){
throw new Exception();
}
finally{
throw new IOException();
}
}
Run Code Online (Sandbox Code Playgroud) 我想在一个查询中插入多个行,如下所示:
insert into EducationInfo (student_id, school_id)
values (
(select id
from STUDENT
where iin in (select distinct iinplt
from TEST_STUDENT
where id_university = 9)), 23421
)
Run Code Online (Sandbox Code Playgroud)
当然是不可能的。我知道我可以这样做:
values(1,23421),
values(2,23421)...
Run Code Online (Sandbox Code Playgroud)
但是如您所见,我不知道student_id列中的ID,并且ID过多。有什么可行的方法吗?
java ×4
spring ×2
sql ×2
sql-server ×2
class ×1
database ×1
inheritance ×1
jpa ×1
kotlin ×1
list ×1
postgresql ×1
spring-boot ×1
spring-el ×1
sql-insert ×1
utf-8 ×1