@SessionAttributes以下使用示例.如何user在向导完成后清除会话属性?在我的例子中,返回/wizard0session属性后仍然存在.我试过了status.setComplete(),session.removeAttribute("user")但它不起作用.
@Controller
@SessionAttributes("user")
public class UserWizard {
@RequestMapping(value = "/wizard0", method = RequestMethod.GET)
public String page1(Model model) {
if(!model.containsAttribute("user")) {
model.addAttribute("user", new User());
}
return "wizard/page1";
}
@RequestMapping(value = "/wizard1", method = RequestMethod.GET)
public String page2(@ModelAttribute User user) {
user.setFirstname(Utils.randomString());
return "wizard/page2";
}
@RequestMapping(value = "/wizard2", method = RequestMethod.GET)
public String page3(@ModelAttribute User user) {
user.setLastname(Utils.randomString());
return "wizard/page3";
}
@RequestMapping(value = "/finish", method = RequestMethod.GET)
public String page4(@ModelAttribute User user, HttpSession …Run Code Online (Sandbox Code Playgroud) 我需要在当前数据库(ALTER DATABASE...)上运行更新脚本,但不能使用隐式名称.是否可以使用某些函数获取当前的db名称并在内部使用ALTER DATABASE(Sql Server 2005及更高版本)?我试过用db_name(),但不行.
select db_name(); 作品
ALTER DATABASE db_name() ... 不起作用
我编译了报告(.jasper文件).我需要从该对象获取一些信息(例如报告名称).怎么做 ?如果我可以创建JasperReport对象,我可以调用getName()它的方法,但我不知道如何.
我有列表List<Long> list,其中包含:[160774,7212775]和Long id = 7212775.我需要检查列表是否包含值为的元素id.怎么做?不幸的是在我的情况下list.contains(id)返回false
我正是这样使用它:
@RequestMapping("/case/{id}")
public String openCase(@PathVariable("id") Long id) {
log.debug(caseDAO.findAllCasesId()); // [160774, 7212775]
log.debug(id); // 7212775
if(caseDAO.findAllCasesId().contains(id)) {
return "case";
} else {
return "404";
}
}
Run Code Online (Sandbox Code Playgroud)
一块DAO(Hibernate,但原生sql在这里):
public List<Long> findAllCasesId() {
String sql = "select id from cases";
SQLQuery query = getSession().createSQLQuery(sql);
return query.list();
}
Run Code Online (Sandbox Code Playgroud)
解决了
问题caseDAO.findAllCasesId()在于,返回列表Object,而不是列表Long.我纠正了这个:
SQLQuery query = getSession().createSQLQuery(sql).addScalar("id", Hibernate.LONG);
非常感谢:Nayuki Minase
我的JSF应用程序中的i18n枚举有问题.当我开始时,我有内部定义文本的枚举.但现在,我在枚举中将密钥绑定到消息包.
我的枚举示例之一:
public enum OrderStatus implements CustomEnum {
PENDING("enum.orderstatus.pending"),
CANCELED("enum.orderstatus.canceled");
/**
* key in message bundle
*/
private String name;
OrderStatus(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
}
Run Code Online (Sandbox Code Playgroud)
在视图层中,我使用如下内容:
<!-- input -->
<h:selectOneMenu value="#{order.status}">
<f:selectItems value="#{flowUtils.orderStatuses}"/>
</h:selectOneMenu>
<!-- output -->
<h:outputText value="#{order.status}"/>
Run Code Online (Sandbox Code Playgroud)
在Java中:
public class FlowUtils {
public List<SelectItem> getOrderStatuses() {
ArrayList<SelectItem> l = new ArrayList<SelectItem>();
for(OrderStatus c: OrderStatus.values()) {
// before i18n
// l.add(new SelectItem(c, c.getName()));
// after i18n
l.add(new SelectItem(c, …Run Code Online (Sandbox Code Playgroud) Spring Security的安全性如何?在Web应用程序中将Spring Security用于银行系统或类似的东西是否足够好?
是否可以使我自己的JSP标记生成的输出更短?例如,定义如下的标签生成5行而不是1.可以避免(不将所有5行连接到标记源中的1)?
<%@ tag description="link" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ attribute name="href" required="true" type="java.lang.String" %>
<%@ attribute name="label" required="false" type="java.lang.String" %>
<a href="<c:url value="${href}"/>">${not empty label ? label : href}</a>
Run Code Online (Sandbox Code Playgroud)
不是解决方案:
<%@ tag description="standard input" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%@ attribute name="href" required="true" type="java.lang.String" description="address relative to web-app context" %><%@ attribute name="label" required="false" type="java.lang.String" description="link label" %><a href="<c:url value="${href}"/>">${not empty label ? label : href}</a>
Run Code Online (Sandbox Code Playgroud) 我正在使用Android Studio版本0.8.2(在Windows7上).当我更改某个文件时会自动保存,这非常令人讨厌.根据这个我已经关闭如下设置(一般情况下,但它不起作用.是否有其他东西使这项工作正常?

我想为我的网络应用程序进行测试,但上下文配置在自动装配时崩溃servletContext.错误如下.servletContext当我在tomcat/jetty上运行web-app时,自动装配工作正常.
java.lang.IllegalStateException:无法加载ApplicationContext ...由以下原因引起:org.springframework.beans.factory.BeanCreationException:创建名为'testController'的bean时出错:注入自动连接的依赖项失败; 嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private javax.servlet.ServletContext com.test.controllers.TestController.servletContext; 嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖项找到类型为[javax.servlet.ServletContext]的匹配bean:期望至少有一个bean可以作为此依赖项的autowire候选者.依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class FirstTest {
@Test
public void doTest() throws Exception {
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
的TestController
@Controller
public class TestController {
@Autowired
private ServletContext servletContext;
...
}
Run Code Online (Sandbox Code Playgroud) 是一种在JSP中访问视图名称的方法(profile在下面的示例中),或者我需要将此名称添加到模型中?
@RequestMapping(value="/user/account", method=RequestMethod.GET)
return "profile";
}
Run Code Online (Sandbox Code Playgroud) java ×3
spring-mvc ×3
collections ×1
enums ×1
jsf-2 ×1
jsp ×1
localization ×1
spring ×1
spring-3 ×1
sql-server ×1
unit-testing ×1