Count.java:
@Component
@Scope(value = "session",proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Count {
Integer i;
public Count() {
this.i = 0;
}
Run Code Online (Sandbox Code Playgroud)
控制器:
@Controller
public class GreetingController {
@Autowired private Count count;
@RequestMapping("/greeting")
public String greetingForm(Model model) {
if(count.i == null) i == 0;
else i++;
model.addAttribute("count",String.valueOf(count.i));
return "greeting";
}
}
Run Code Online (Sandbox Code Playgroud)
但每次我运行这个控制器(/问候语),它甚至在我关闭浏览器时总是增加i,所以如何在Singleton Controller中使用这个Session Scoped Component?
spring dependency-injection spring-mvc spring-ioc spring-boot
这是我的Tag和Post Entity类:
@Entity
class Tag(
@get:NotBlank
@Column(unique = true)
val name: String = "",
val description: String = ""
) {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
val id: Int? = null
@ManyToMany(mappedBy = "tags")
val posts: MutableSet<Post> = mutableSetOf()
@CreationTimestamp
lateinit var createDate: Date
@UpdateTimestamp
lateinit var updateDate: Date
fun addPost(post: Post) {
this.posts.add(post)
post.tags.add(this)
}
}
@Entity
class Post(
@get:NotBlank
var name: String = "",
val content: String = ""
) {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
val id: Int? = …Run Code Online (Sandbox Code Playgroud) 我有一个可观察的:
messages: string[] = ['a', 'b', 'c'];
const source = from(messages)
Run Code Online (Sandbox Code Playgroud)
如何延迟它,以便当有人订阅它时,它会延迟 n 秒来发出项目?所以:
source.subscribe(i => console.log(i));
// output ...n seconds... 'a' ...n seconds... 'b' ...n seconds... 'c'
Run Code Online (Sandbox Code Playgroud) 编写操作系统(Windows)或启动CD的语言是什么?
最近,我做了一个chrome ext,但是任何人都可以通过将crx重命名为zip并提取它来阅读其源代码,我如何保护我的SC?
<a href="url">A link</a>
$.each($('a'), function(index,value){
alert (value)
});
Run Code Online (Sandbox Code Playgroud)
它会警告:url.为什么会这样?
<form onsubmit="return false">
Run Code Online (Sandbox Code Playgroud)
那是有效的.但
<form method="post" action="" onsubmit="off()">
function off(){return false);
Run Code Online (Sandbox Code Playgroud)
不行
我将尝试忽略其他细节并使其简短:
@Entity
public class User
@UniqueEmail
@Column(unique = true)
private String email;
}
@Component
public class UniqueEmailValidatior implements ConstraintValidator<UniqueEmail,String>, InitializingBean {
@Autowired private UserService userService;
@Override
public void initialize(UniqueEmail constraintAnnotation) {
}
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if(userService == null) throw new IllegalStateException();
if(value == null) return false;
return !userService.isEmailExisted(value);
}
}
Run Code Online (Sandbox Code Playgroud)
这将在 Spring 中进行验证(Spring MVC@Valid或注入Validatorusing @Autowire)时起作用,一切都会好起来的。但是一旦我使用 Spring Data JPA 保存实体:
User save = userRepository.save(newUser);
Run Code Online (Sandbox Code Playgroud)
Hibernate 将尝试在UniqueEmailValidatior不注入UserServicebean 的情况下实例化一个新的。那么如何让 …
javascript ×4
spring ×3
spring-boot ×2
anchor ×1
boot ×1
forms ×1
function ×1
html ×1
jquery ×1
kotlin ×1
observable ×1
osdev ×1
rxjs ×1
spring-data ×1
spring-ioc ×1
spring-mvc ×1
windows ×1