是否有可能告诉我的JSF实现将空数转换为null.到目前为止,我总是得到0(相应的复杂类型).
对于空字符串有javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL,但我无法找到任何数字.顺便说一下:不,我不能使用vm-argument:-Dorg.apache.el.parser.COERCE_TO_ZERO = false
自定义数字转换器是我唯一的可能吗?
我的表单有几个"提交"按钮,一些字段的验证取决于按下哪个.如何在我的自定义验证器中找到它?
当我在spring mvc中调用EntityManager.persist()时出现异常,虽然@Transactional在方法上添加了它,但它可以在不集成spring mvc的情况下工作:
HTTP ERROR 500
Problem accessing /ssshp/addDept/wwewd. Reason:
No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call
Caused by:
javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:278)
at com.sun.proxy.$Proxy49.persist(Unknown Source)
at cn.ziav.ssshp.facade.SpringFacadeImpl.createDept(SpringFacadeImpl.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at …Run Code Online (Sandbox Code Playgroud) 我正在尝试将HTMLstyle-attribute 的内容解析为Map.到目前为止这是我的代码.困扰我的是方法的冗余调用String::split.怎么可以这个优化?
final String style = "padding-left: 6px; font-weight: bold";
final Map<String, String> result = Arrays.stream(style.split(";")) //
.map(String::trim) //
.filter(s -> s.split(":").length <= 2) // invalid
.collect(Collectors.toMap(s -> s.split(":")[0].trim(),
s -> s.split(":").length > 1 ? s.split(":")[1].trim() : ""));
Run Code Online (Sandbox Code Playgroud) 我目前正在努力在某些条件下返回 http 响应状态代码。假设 taskService.getNewTasks 的返回对象为 null。在这种情况下,我想返回状态代码 404。在某些异常情况下,我想返回一些 50x,依此类推。
到目前为止我的代码
@RestController
public class TaskController {
@Autowired
private TaskService taskService;
@GetMapping(path = "gettasks")
private Future<Tasks> getNewTasks() {
return taskService.getNewTasks();
}
...
}
@Service
public class TaskService {
@Async
public Future<Tasks> getNewTasks() {
...
return CompletableFuture.completedFuture(tasks);
}
}
Run Code Online (Sandbox Code Playgroud) 我目前正在努力解析类似于版本的String。
到目前为止v(\\d+)_(\\d+)(?:_(\\d+))?,我的正则表达式应该与以下格式的String匹配:v Version _ InterimVersion _ PatchVersion。我的目标是,最后一个匹配组(_ PatchVersion)是可选的。
我的问题是可选部分。字符串v1_00会给我3的a matcher.groupCount值。我本来希望groupCount为2。所以我猜我的正则表达式是错误的,或者是我在理解上有困难matcher.groupCount。
public static void main(final String[] args) {
final String versionString = "v1_00";
final String regex = "v(\\d+)_(\\d+)(?:_(\\d+))?";
final Matcher matcher = Pattern.compile(regex).matcher(apiVersionString);
if (matcher.matches()) {
final int version = Integer.parseInt(matcher.group(1));
final int interimVersion = Integer.parseInt(matcher.group(2));
int patchVersion = 0;
if (matcher.groupCount() == 3) {
patchVersion = Integer.parseInt(matcher.group(3));
}
// ...
}
}
Run Code Online (Sandbox Code Playgroud) 我想尝试Spring 3.1 Cache Abstraction,使用@Cachable注释一些方法。在没有参数的方法上,这很好用。对于带有参数的方法则不是。在文档(http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/cache.html)中找不到任何内容。
有人遇到同样的事情吗?
方法调用为:
@Cachable("countries")
public List<ConfigEntity> findCountries(Locale locale) {
ConfigSearchDescription desc = new ConfigSearchDescription();
// ...
return findConfigs(desc);
}
Run Code Online (Sandbox Code Playgroud)
谢谢乔尼
java ×4
myfaces ×2
spring ×2
spring-mvc ×2
asynchronous ×1
caching ×1
el ×1
hibernate ×1
jsf ×1
jsf-2 ×1
lambda ×1
primefaces ×1
regex ×1
spring-boot ×1
tomcat ×1