GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update SpringInterviewQuestions.md · luyuhui0209/JavaGuide@2bab595

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/system-design/framework/spring
    • SpringInterviewQuestions.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/system-design/framework/spring/SpringInterviewQuestions.md‎

Copy file name to clipboardExpand all lines: docs/system-design/framework/spring/SpringInterviewQuestions.md
+39-1Lines changed: 39 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Spring 官网列出的 Spring 的 6 个特征:
5151
- **Spring Web** : 为创建Web应用程序提供支持。
5252
- **Spring Test** : 提供了对 JUnit 和 TestNG 测试的支持。
5353

54+
55+
5456
## 谈谈自己对于 Spring IoC 和 AOP 的理解
5557

5658
### IoC
@@ -276,7 +278,43 @@ public OneService getService(status) {
276278

277279
当`@Transactional`注解作用于类上时,该类的所有 public 方法将都具有该类型的事务属性,同时,我们也可以在方法级别使用该标注来覆盖类级别的定义。如果类或者方法加了这个注解,那么这个类里面的方法抛出异常,就会回滚,数据库里面的数据也会回滚。
278280

279-
在`@Transactional`注解中如果不配置`rollbackFor`属性,那么事物只会在遇到`RuntimeException`的时候才会回滚,加上`rollbackFor=Exception.class`,可以让事物在遇到非运行时异常时也回滚
281+
在`@Transactional`注解中如果不配置`rollbackFor`属性,那么事物只会在遇到`RuntimeException`的时候才会回滚,加上`rollbackFor=Exception.class`,可以让事物在遇到非运行时异常时也回滚。
282+
283+
## 如何使用JPA在数据库中非持久化一个字段?
284+
285+
假如我们有有下面一个类:
286+
287+
```java
288+
Entity(name="USER")
289+
public class User {
290+
291+
@Id
292+
@GeneratedValue(strategy = GenerationType.AUTO)
293+
@Column(name = "ID")
294+
private Long id;
295+
296+
@Column(name="USER_NAME")
297+
private String userName;
298+
299+
@Column(name="PASSWORD")
300+
private String password;
301+
302+
private String secrect;
303+
304+
}
305+
```
306+
307+
如果我们想让`secrect` 这个字段不被持久化,也就是不被数据库存储怎么办?我们可以采用下面几种方法:
308+
309+
```java
310+
static String transient1; // not persistent because of static
311+
final String transient2 = “Satish”; // not persistent because of final
312+
transient String transient3; // not persistent because of transient
313+
@Transient
314+
String transient4; // not persistent because of @Transient
315+
```
316+
317+
一般使用后面两种方式比较多,我个人使用注解的方式比较多。
280318

281319
## 参考
282320

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.