小编Tro*_*dor的帖子

在Spring-mvc拦截器中,如何访问处理程序控制器方法?

在Spring-mvc拦截器中,我想访问处理程序控制器方法

public class CustomInterceptor implements HandlerInterceptor  {
    public boolean preHandle(
        HttpServletRequest request,HttpServletResponse response, 
            Object handler) {

        log.info(handler.getClass().getName()); //access to the controller class
        //I want to have the controller method
        ...
        return true;
   }
   ...
}
Run Code Online (Sandbox Code Playgroud)

我已经找到 :

如何对获得控制器,方法名,在弹簧拦截-prehandle法

但它只能解决.我希望方法名称可以访问注释.

java spring-mvc interceptor

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

JQuery UI继承多态

有没有办法在jQuery UI中的窗口小部件的继承中具有多态性?

例如,我想做类似的事情:

$.widget('tr.fatherClass', {
  getValue: function() {
    return null;
  }
  ...
});
// sonClass1: extends from the father
$.widget('tr.sonClass1', $.tr.fatherClass, {
  getValue: function() {
    return this._fooFunction1();
  }
  ...
});
// sonClass2: extends from the father
$.widget('tr.sonClass2', $.tr.fatherClass, {
  getValue: function() {
    return this._fooFunction2();//
  }
  ...
});
// create an instance of a "sonClass"
$('#foo1').sonClass1(options);  
$('#foo2').sonClass2(options);  
Run Code Online (Sandbox Code Playgroud)

然后我想使用方法"getValue"而不知道子类的名称:

$('#foo1').fatherClass('getValue'); // run _fooFunction1() of sonClass1
$('#foo2').fatherClass('getValue'); // run _fooFunction2() of sonClass2
Run Code Online (Sandbox Code Playgroud)

但这不可能:

jquery.js:250 Uncaught Error: cannot call methods on variable prior to …
Run Code Online (Sandbox Code Playgroud)

javascript polymorphism inheritance jquery-ui widget

11
推荐指数
1
解决办法
460
查看次数

在jpa标准中,"如果至少有一行返回true"

我正在尝试使用JPA(eclipselink)中的条件api创建后续句子,它很简单地询问某些类别中是否存在某些用户

我想要的句子:

SELECT 
  CASE 
     WHEN EXISTS
          (SELECT * FROM user WHERE category = ?)
     THEN true
     ELSE false
  END 
bind => [10]
Run Code Online (Sandbox Code Playgroud)

我尝试使用此代码:

CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Boolean> criteriaQuery = criteriaBuilder.createQuery(Boolean.class);
Root<T> root = criteriaQuery.from(tclass);

Subquery<T> subquery = criteriaQuery.subquery(tclass);
Root<T> subroot = subquery.from(tclass);
subquery.select(subroot);

Predicate subPredicate = criteriaBuilder.equal(subroot.get("category"),category);
subquery.where(subPredicate);

Predicate predicateExists = criteriaBuilder.exists(subquery);

Case<Boolean> booleancase = criteriaBuilder.<Boolean>selectCase();
Expression<Boolean> booleanExpression =
    booleancase.when(predicateExists,true)
    .otherwise(false);

criteriaQuery.select(booleanExpression);

TypedQuery<Boolean> typedQuery = entityManager.createQuery(criteriaQuery);
typedQuery.getResultList();
Run Code Online (Sandbox Code Playgroud)

可悲的是我的句子是跟随,我想删除最后一个"来自用户":

SELECT 
  CASE 
      WHEN EXISTS
          (SELECT ? FROM user t1 WHERE (t1.category …
Run Code Online (Sandbox Code Playgroud)

java sql database jpa criteria-api

8
推荐指数
1
解决办法
2428
查看次数

拆分C ++类声明

我想知道我是否可以拆分C ++类声明

原班

    class P
    {
        private: 
           int id;
           //some really secret method
           int secretMethod();
       protected:
           int x;
       public:
           P();
           int getX();
    };
Run Code Online (Sandbox Code Playgroud)

我只想在.h中显示public和protected方法和属性,并在其他地方声明private,而类的用户看不到它。

想要的类声明:

    class P
    {
       protected:
           int x;
       public:
           P();
           int getX();
    };
Run Code Online (Sandbox Code Playgroud)

编辑:我想要的是:

  1. 我可以更改类的实现,并且对于该类的用户是透明的
  2. 用户更容易看到更少的信息
  3. 如果我更改类的实现,请更改私有属性和方法,我不想为该类的用户更改.h

c++

5
推荐指数
1
解决办法
5824
查看次数

在Spring webmvc项目中,将extern文件夹用于模板

我试图外部化我的spring webmvc proyect的模板文件夹,我需要此功能,因为设计人员要经常修改html。并为他难于编辑一个战争文件。我使用百里香叶作为templateResolver

<bean id="templateResolver" 
    class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">

    <property name="prefix" value="file:/opt/templates/" />
    <property name="suffix" value=".html" />
    <property name="templateMode" value="HTML5" />
    <property name="cacheable" value="false" />
</bean>
Run Code Online (Sandbox Code Playgroud)

我尝试使用这条线,但是没有用

<property name="prefix" value="file:/opt/templates/" />
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

java configuration spring spring-mvc thymeleaf

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

如何在Thymeleaf中配置基本URL?

我使用Thymeleaf作为Web应用程序的模板.

当我建立链接时,我使用这样的URL:

<img class="info" 
    src="../../../resources/img/image.png"
    th:src="@{/resources/img/image.png}" /> 
Run Code Online (Sandbox Code Playgroud)

如何在Thymeleaf中配置基本URL?

我需要这个,因为我的应用程序在当前URL中运行:

http://localhost:8080/myapp
Run Code Online (Sandbox Code Playgroud)

它工作正常,但然后重定向到:

http://www.myapp.com/
Run Code Online (Sandbox Code Playgroud)

然后搜索图像:

http://www.myapp.com/myapp/resources/img/image.png
Run Code Online (Sandbox Code Playgroud)

代替:

http://www.myapp.com/resources/img/image.png
Run Code Online (Sandbox Code Playgroud)

我想要的东西:

<property name="baseURL" value="http://www.myapp.com"/>
Run Code Online (Sandbox Code Playgroud)

html spring-mvc thymeleaf

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

如何使用argparse通过python脚本中的管道发送参数?

我必须创建一个可以与Linux管道一起使用的python脚本

我想运行一个脚本,其中一些参数可以通过管道或同一行发送

将脚本与预期输出结合使用的一些示例:

echo "a" > list.txt
echo "b" >> list.txt

./run.py p1 p2   # ['p1', 'p2'] expected output
cat list.txt | ./run.py  # ['a', 'b'] expected output
cat list.txt | ./run.py p1 p2 # ['p1', 'p2', 'a', 'b'] expected output
Run Code Online (Sandbox Code Playgroud)

我试过了:

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('args', nargs=argparse.REMAINDER)
args = parser.parse_args().args
print args
Run Code Online (Sandbox Code Playgroud)

它仅适用于同一行中的参数:

./run.py p1 p2  #['p1', 'p2'] OK
cat list.txt | ./run.py  # []  Not OK
cat list.txt | ./run.py p1 p2 # ['p1', 'p2'] expected output
Run Code Online (Sandbox Code Playgroud)

python bash argparse

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