小编Jaa*_*nus的帖子

Java Spring JDBC模板问题

public List<Weather> getWeather(int cityId, int days) {
    logger.info("days: " + days);
    return getSimpleJdbcTemplate().query("SELECT weather.id, cities.name, weather.date, weather.degree " +
                                        "FROM weather JOIN cities ON weather.city_id = cities.id " +
                                        "WHERE weather.city_id = ? AND weather.date BETWEEN now()::date AND (now() + '? days')::date",
                                        this.w_mapper, cityId, days);
}
Run Code Online (Sandbox Code Playgroud)

错误:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [SELECT weather.id, cities.name, weather.date, weather.degree FROM weather JOIN cities ON weather.city_id = cities.id WHERE weather.city_id = ? AND weather.date BETWEEN now()::date AND (now() …
Run Code Online (Sandbox Code Playgroud)

java spring jdbc spring-mvc

3
推荐指数
2
解决办法
4351
查看次数

C++字符串操作,字符串下标超出范围

基本上应该做的是:

1)获取字符串并找到其长度

2)遍历所有元素key并将所有独特成员放入start(playfair密码)

Table::Table(string key) {
    int i;
    for(i = 0; i < key.length(); i++) {
        if(start.find(key[i]) == string::npos) { //start is empty string
            start[start.length()] = key[i]; // this line gives error
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

错误:

在此输入图像描述

c++ string visual-studio visual-c++

3
推荐指数
1
解决办法
2367
查看次数

Java Spring表单标记问题

我正在使用JSP,这是我的contacts.jsp

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<html>
<head>
    <title>Spring 3.0 MVC series: Contact manager</title>
</head>
<body>
<h2>Contact Manager</h2>
<form:form method="post" action="addContact.html">

    <table>
        <tr>
            <td><form:label path="firstName">First Name</form:label></td> // LABEL
            <td><form:input path="firstName" /></td>
        </tr>
        <tr>
            <td><form:label path="lastName">Last Name</form:label></td>
            <td><form:input path="lastName" /></td>
        </tr>
        <tr>
            <td><form:label path="lastName">Email</form:label></td>
            <td><form:input path="email" /></td>
        </tr>
        <tr>
            <td><form:label path="lastName">Telephone</form:label></td>
            <td><form:input path="telephone" /></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="Add Contact"/>
            </td>
        </tr>
    </table>  

</form:form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我改变form:label path="firstName"form:label path="firstname",为什么Tomcat启动时抛出的错误?模型是否只需要输入路径,因为输入路径中的值是它将使用的值?

编辑:

我应该使用它form:label tag,为什么要使用它?

java spring jsp spring-mvc

3
推荐指数
1
解决办法
1万
查看次数

源文件夹不在Java构建类路径上,创建Java包

我试图在排序下创建一个包合并,但它说:

源文件夹不在Java构建类路径上

在此输入图像描述

所以我右键单击sort文件夹,并尝试将其添加到Java构建类路径.但只有选项有排除,所以这意味着它应该已经包含在类路径中. 在此输入图像描述

那么如何在排序下创建包呢?

编辑:

添加.classpath:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
    <classpathentry kind="output" path="bin"/>
</classpath>
Run Code Online (Sandbox Code Playgroud)

java eclipse class classpath package

3
推荐指数
2
解决办法
4万
查看次数

比较undefined和false非常奇怪的行为

我在控制台中有这个输出:

console.log((!undefined)==(!false)) // true (fine)
console.log((!!undefined)==(!!false)) // true (still fine)
Run Code Online (Sandbox Code Playgroud)

据我所知,!!x==x不是吗?

console.log((undefined)==(false)) // false
Run Code Online (Sandbox Code Playgroud)

谁能告诉我为什么这会返回错误?

是不正确的!!false==false!!undefined==undefined

javascript comparison logic comparison-operators

3
推荐指数
1
解决办法
239
查看次数

使用hibernate保存/更新对象

我的班级Foo有方法:

 protected void saveMany(Collection<T> many) {  
    for(Object one : many) {
            one = session.merge(one); // also tried this commented out
            session.saveOrUpdate(one); // session.merge(one);   
        }
Run Code Online (Sandbox Code Playgroud)

试图使用saveOrUpdate并合并,但两者都给了我这个例外:

Error: Invocation of method 'saveMany' in class Foo threw exception class org.hibernate.HibernateException : org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [Bar#581301]
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

边注:

当我截断我的表时,保存部分工作,但是当我填充表时,再次运行此方法,从而更新表,它失败,具有此异常

java generics hibernate

3
推荐指数
1
解决办法
2万
查看次数

Spring Security过滤器具有多个URL拦截映射

我正在学习本教程:http: //www.mkyong.com/spring-security/spring-security-hello-world-example/

在里面 spring-security-xml

<http auto-config="true">
    <intercept-url pattern="/welcome*" access="ROLE_USER" />
</http>
Run Code Online (Sandbox Code Playgroud)

在web.xml中,我们必须定义实际的过滤器

<!-- Spring Security -->
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>
              org.springframework.web.filter.DelegatingFilterProxy
            </filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

所以我没有得到这个,我们将截取映射到2个地方的2个网址.去/welcome*/*.为什么我们需要这两个?我在这里错过了什么吗?

java spring spring-security interceptor

3
推荐指数
1
解决办法
5572
查看次数

使用Thymeleaf时,Spring security sessionscope似乎为null

当登录失败并带有spring security时,它会抛出异常并将其显示在我的JSP中,如下所示:

<c:if test="${not empty error}">
    <div class="errorblock">
        Your login attempt was not successful, try again.<br /> Caused :
        ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
    </div>
</c:if>
Run Code Online (Sandbox Code Playgroud)

现在我正在从JSP更改为Thymeleaf并尝试执行相同的操作,但是当登录失败时,sessionScope变量似乎为null.

<div th:if="${error}" class="errorblock" th:text="'testing ' + ${sessionScope}">

</div>
Run Code Online (Sandbox Code Playgroud)

打印出来testing null.当我将视图解析器更改回JSP时,它可以很好地工作.我想我做错了什么.有什么建议?

java spring jsp spring-security thymeleaf

3
推荐指数
2
解决办法
6332
查看次数

任务计划程序 PowerShell 启动进程未运行

我在 Windows 10 上有这个简单的脚本,它在执行时工作正常,但从任务计划程序运行时无法启动记事本。Stop-Process 完美运行,Start-Process 不运行。当我按需运行它时,它会关闭记事本,然后在不打开记事本的情况下继续运行,该任务也不会关闭。

Stop-Process -processname notepad
Start-Process "C:\Windows\system32\notepad.exe"
Run Code Online (Sandbox Code Playgroud)

这是它被配置为运行的方式。 在此处输入图片说明 在此处输入图片说明 我尝试过的事情,但仍然不起作用。

  1. 首先,我在管理员帐户下运行。
  2. 在任务调度程序中,检查以最高权限运行。
  3. 我曾尝试-ExecutionPolicy Bypass-ExecutionPolicy RemoteSigned
  4. 根据安全策略已授予我的用户Logon as batch工作权限
  5. 关闭 UAC

powershell scheduled-tasks start-process

3
推荐指数
1
解决办法
3662
查看次数

解析Java String到目前为止

日志(2个不同的日期):

START TIME BEFORE PARSE: 06/27/2012 09:00
START TIME AFTER PARSE : Thu Mar 06 09:00:00 EET 2014


START TIME BEFORE PARSE: 07/06/2012 09:00
START TIME AFTER PARSE : Thu Jun 07 09:00:00 EEST 2012
Run Code Online (Sandbox Code Playgroud)

代码:

DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
            Date date = sdf.parse(time);
            System.out.println("TIME BEFORE PARSE: " + time);
            System.out.println("TIME AFTER PARSE : " + date);
Run Code Online (Sandbox Code Playgroud)

为什么今年会搞乱?如何让它工作?

java parsing date date-format

2
推荐指数
1
解决办法
658
查看次数