我对Java 8 Time API中的日期解析感到有点气馁.
以前我可以轻松写:
String date = "04.2013";
DateFormat df = new SimpleDateFormat("MM.yyyy");
Date d = df.parse(date);
Run Code Online (Sandbox Code Playgroud)
但是现在如果我使用LocalDate并像这样做:
String date = "04.2013";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.yyyy");
LocalDate ld = LocalDate.parse(date, formatter);
Run Code Online (Sandbox Code Playgroud)
我收到一个例外:
java.time.format.DateTimeParseException: Text '04' could not be parsed at index 0
java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1948)
java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1850)
java.time.LocalDate.parse(LocalDate.java:400)
java.time.LocalDate.parse(LocalDate.java:385)
com.luxoft.ath.controllers.JsonController.region(JsonController.java:38)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:483)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Run Code Online (Sandbox Code Playgroud)
如果我将字符串格式更改为"yyyy-MM-dd",即使没有格式化程序,一切也能正常工作:
String date = "2013-04-12";
LocalDate …Run Code Online (Sandbox Code Playgroud) 我找不到使用Thymeleaf从URL获取属性的任何解决方案.例如,对于URL:
somesite.com/login?error=true
Run Code Online (Sandbox Code Playgroud)
我需要获得"错误"属性值.我也在使用SpringMVC,如果它可能有用.
如何在鼠标悬停时禁用IntelliJ IDEA中的自动显示提示?

编辑:
如果使用不正确的参数调用现有方法,则此提示可能非常大.这很不舒服.
PyCharm中有相同的行为:

和WebStorm:

我正在使用带有Spring JdbcTemplate的Logback来记录我的SQL查询.我的配置包含下一行:
<logger name="org.springframework.jdbc.core.JdbcTemplate" level="DEBUG" />
Run Code Online (Sandbox Code Playgroud)
但是这仅记录带有通配符的查询而?没有参数列表.
在这里,我发现了一些如何使用log4j实现参数记录的答案.但我不想切换到log4j.
那么如何通过Logback接收JdbcTemplate的参数列表呢?
编辑
实际上,NamedParameterJdbcTemplate如果重要的话,我正在使用它.
我正在使用Spring MVC与Thymeleaf和Tomcat,我希望能够更新静态数据(html页面)而无需重新部署.在我的应用程序中,html是由Spring控制器映射的.即使是JRebel也无济于事.它更新了java类,但对视图没有任何作用.我该怎么做才能解决这个问题?也许对于html我需要一些像Jasper for JSP的监听器机制,或者我应该为Spring控制器禁用一些缓存?
我有工作代码直到昨天和今天我看到异常,com.google.gdata.util.ResourceNotFoundException 同时从我的gae代码阅读谷歌文档如下.请注意,最后一行是抛出此异常.
DocsService client = new DocsService("sakshum-YourAppName-v1");
client.setOAuthCredentials(oauthParameters,
new OAuthHmacSha1Signer());
URL feedUrl = new URL(
"https://docs.google.com/feeds/default/private/full/");
DocumentQuery dquery = new DocumentQuery(feedUrl);
dquery.setTitleQuery(title);
dquery.setTitleExact(true);
dquery.setMaxResults(10);
DocumentListFeed resultFeed = client.getFeed(dquery,
DocumentListFeed.class);
log.info("feed size:" + resultFeed.getEntries().size());
if (resultFeed.getEntries().size() != 1) {
log.info("More than one document is found with same title.");
return null;
}
emailBody = new StringBuffer("");
for (DocumentListEntry entry : resultFeed.getEntries()) {
String docId = entry.getDocId();
String docType = entry.getType();
log.info("Getting doc from url with docId:" + docId
+ " docType:" …Run Code Online (Sandbox Code Playgroud) 我的SpringMVC控制器中有下一个工作代码:
@RequestMapping(value = "/register", method = RequestMethod.GET)
public void registerForm(Model model) {
model.addAttribute("registerInfo", new UserRegistrationForm());
}
@RequestMapping(value = "/reg", method = RequestMethod.POST)
public String create(
@Valid @ModelAttribute("registerInfo") UserRegistrationForm userRegistrationForm,
BindingResult result) {
if (result.hasErrors()) {
return "register";
}
userService.addUser(userRegistrationForm);
return "redirect:/";
}
Run Code Online (Sandbox Code Playgroud)
简而言之,create尝试验证UserRegistrationForm.如果表单有错误,它会将用户留在填充表单字段的同一页面上,其中将显示错误消息.
现在我需要将相同的行为应用到另一个页面,但在这里我有一个问题:
@RequestMapping(value = "/buy/{buyId}", method = RequestMethod.GET)
public String buyGet(HttpServletRequest request, Model model, @PathVariable long buyId) {
model.addAttribute("buyForm", new BuyForm());
return "/buy";
}
@RequestMapping(value = "/buy/{buyId}", method = RequestMethod.POST)
public String …Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试进入 tensorflow,但感觉有点傻。TF 中的 log_loss 与 sklearn 的不同吗?
这是我的代码中的一些行,我是如何计算的:
from sklearn.metrics import log_loss
tmp = np.array(y_test)
y_test_t = np.array([tmp, -(tmp-1)]).T[0]
tf_log_loss = tf.losses.log_loss(predictions=tf.nn.softmax(logits), labels=tf_y)
with tf.Session() as sess:
# training
a = sess.run(tf.nn.softmax(logits), feed_dict={tf_x: xtest, keep_prob: 1.})
print(" sk.log_loss: ", log_loss(y_test, a,eps=1e-7 ))
print(" tf.log_loss: ", sess.run(tf_log_loss, feed_dict={tf_x: xtest, tf_y: y_test_t, keep_prob: 1.}))
Run Code Online (Sandbox Code Playgroud)
我得到的输出
Epoch 7, Loss: 0.4875 Validation Accuracy: 0.818981
sk.log_loss: 1.76533018874
tf.log_loss: 0.396557
Epoch 8, Loss: 0.4850 Validation Accuracy: 0.820738
sk.log_loss: 1.77217639627
tf.log_loss: 0.393351
Epoch 9, Loss: 0.4835 Validation …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,应该在某些目录中保存内容(用户头像),例如C:\ avadir.在我的应用程序中,我正在使用SpringMVC.我需要显示用户定义的头像.为此,我必须配置Tomcat以使用此外部目录.我在我的ROOT.xml中有这样的opthions ,放在%CATALINA_HOME%\ conf\Catalina\localhost中:
<Context path="/ava" docBase="c:/avadir" debug="0" reloadable="true" crossContext="true" />
Run Code Online (Sandbox Code Playgroud)
我的下一个设置servlet-context.xml:
<resources mapping="/ava/**" location="/ava/" />
Run Code Online (Sandbox Code Playgroud)
设置完这个设置后,我仍然无法通过url localhost:8080/ava/file.jpg访问放在C:\ avadir\file.jpg中的文件.有没有遗漏的东西?
java ×3
spring-mvc ×3
spring ×2
thymeleaf ×2
tomcat ×2
date ×1
gdata-api ×1
java-8 ×1
java-time ×1
jdbctemplate ×1
logback ×1
loss ×1
pycharm ×1
scikit-learn ×1
templates ×1
tensorflow ×1
validation ×1
webstorm ×1