我对 Spring MVC 有很长时间(到目前为止很开心)的经验,但最近我对 Wicket 产生了兴趣。
我的问题也是关于如何处理(使用 Wicket)DI、事务管理、JDBC 连接和所有这些东西?可以将 Springsource 套件的某些部分与 Wicket 混合使用吗? Wicket 口和焊接? Wicket 口和吉斯?
最佳答案
Wicket 是一个表示层框架。它不会处理 DI、事务或连接。
但它可以很容易地与许多框架集成,包括 Spring、Guice(官方 Wicket 模块,wicket-spring 和 wicket-guice)和 CDI/Weld(wicket-cdi,来自 Igor Vaynberg 的一个附带项目,Wicket 之一提交者)。
Wicket Wiki: Integration guides
下面是一个简单的带有 Spring 的 Wicket 应用程序。事务位是普通的旧 Spring 配置,所以我没有费心包括它们。
HelloWorldService.java
public class HelloWorldService {
private String message;
public void setMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
应用程序上下文.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="helloWorldService" class="minimal.wicketspring.HelloWorldService">
<property name="message" value="Hello, World!" />
</bean>
</beans>
WicketApplication.java
public class WicketApplication extends WebApplication {
@Override
public void init() {
super.init();
getComponentInstantiationListeners().add(new SpringComponentInjector(this));
}
@Override
public Class<HomePage> getHomePage() {
return HomePage.class;
}
}
主页.java
public class HomePage extends WebPage {
@SpringBean
private HelloWorldService helloWorldService;
public HomePage() {
add(new FeedbackPanel("feedback"));
add(new Link<Void>("link") {
@Override
public void onClick() {
info(helloWorldService.getMessage());
}
});
}
}
主页.html
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>
<div wicket:id="feedback"></div>
<a wicket:id="link">Show Message</a>
</body>
</html>
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>wicket.wicket-spring</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>minimal.wicketspring.WicketApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>wicket.wicket-spring</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
关于spring-mvc - Spring MVC 还是 Wicket?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9507239/