假设您正在创建类型为 的新实体,假设您知道ID 为 1 的a存在,那么UserUser 具有嵌套对象,是否有一种简单的方法可以在 new和 existing之间形成关联?BillingBillingUserBilling
假设获取一个Billing对象设置给用户是一个昂贵的操作,因此获取整个 Billing 对象并将其设置给用户的解决方案不是一个选项。
我的问题是,是否有使用 spring 数据保存实体与其嵌套对应物之间的这种关系的快捷方法?
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int userId;
private String name;
@ManyToOne
@JoinColumn(name = "billing_id")
private Billing userBill;
// constructor
// getters and setters
}
Run Code Online (Sandbox Code Playgroud)
例如在 sudo 代码中:
User bob = new User();
bob.billingId.id = 1;
userRepository.save(bob);
Run Code Online (Sandbox Code Playgroud) 通过此设置,我可以完美地提供静态资源,但是我必须逐个文件地定义允许提供服务的文件。
我当前的用例是目录中的任何内容都/resources/public/应该允许客户端访问。
我已经尝试过 one liner /resources/public/**,但/public/**仍然不允许访问我收到 403 的所有公共资源。因此,在我的 http 配置中,我已经开始定义允许的文件扩展名,但我不喜欢这种方法,因为我的 web 应用程序中有很多不同的扩展名。
我的问题是,如何允许访问所有文件,而/resources/public/不必为每个文件扩展名定义 ant 匹配器,或者我只是小气?
Spring WebSecurityConfigurerAdapter- 根据 jmw5598 的答案进行编辑。
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity http) {
http
.authorizeRequests()
.authorizeRequests()
.antMatchers(
"/public/**",
"/.svg", "/.ico", "/.eot", "/.woff2",
"/.ttf", "/.woff", "/.html", "/.js",
"/.map", "/*.bundle.*",
"/index.html", "/", "/home", "/dashboard")
.permitAll()
.anyRequest().authenticated();
}
Run Code Online (Sandbox Code Playgroud)
服务网络应用程序的控制器:
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600)
@Controller
public class AngularWebAppController …Run Code Online (Sandbox Code Playgroud) Windows窗口计时器有一点问题.这是一个非常基本的问题,但我环顾四周,似乎无法找到答案(我可能应该得到一记耳光).
我需要能够获得计时器的值,无论其经过的时间是否大于500毫秒的间隔.
就像是
Timer.Elapsed >= 500
Run Code Online (Sandbox Code Playgroud)