假设我有这个注释
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Name
{
String value();
}
Run Code Online (Sandbox Code Playgroud)
这将按如下方式使用
@Name("name1")
public static Foo foo = new Foo();
Run Code Online (Sandbox Code Playgroud)
我的项目源文件中有多个这些。是否有一种相当简单的方法来搜索和收集所有以 开头的“foo” @Name?换句话说,我想写一个方法来返回一个Set<Foo>包含这些的。
谢谢!!!
我想创建一个注释,它搜索以注释中给出的单词开头的方法名称并执行此方法。
我是注释的新手,我知道有一些内置注释,例如:
@override, @suppressWarnigs, @documented, @Retention, @deprecated, @target
Run Code Online (Sandbox Code Playgroud)
有没有更多的注释?
我已经测试了自动连接的行为,以防应用程序上下文 xml 文件中缺少 context:annotation-config 元素。令我惊讶的是,它的工作原理是一样的。
所以这是我的问题:即使应用程序上下文配置文件中缺少 context:annotation-config 元素,如何在 ApplicationContext 中注册 AutowiredAnnotationBeanPostProcessor,或者还有什么机制使此配置起作用?
我使用的是 Spring 版本 3.0.6.RELEASE 这是项目 pom 文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven- v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples.spring</groupId>
<artifactId>spring-utility</artifactId>
<version>1.0.0.CI-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Spring Utility</name>
<url>http://www.springframework.org</url>
<description>
<![CDATA[
This project is a minimal jar utility with Spring configuration.
]]>
</description>
<properties>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
<spring.framework.version>3.0.6.RELEASE</spring.framework.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin> …Run Code Online (Sandbox Code Playgroud) 我试图在由 IN 子句组成的 SELECT QUERY 中传递多个值。我想使用 mybatis 执行以下查询:
SELECT * FROM DBA_COMPARISON_ROW_DIF WHERE SCAN_ID in (#{childScanIDs})
Run Code Online (Sandbox Code Playgroud)
其中childScanIDs变量由多个逗号分隔的值组成。我将这些值作为由逗号分隔的所有值组成的字符串传递。下面是映射器接口中使用的方法。
@Select(getDifferencesByScanIDs)
@Results({
@Result(property="owner", column="OWNER"),
@Result(property="comparisonName", column="COMPARISON_NAME"),
@Result(property="scanID", column="SCAN_ID"),
@Result(property="localRowID", column="LOCAL_ROWID"),
@Result(property="remoteRowID", column="REMOTE_ROWID"),
@Result(property="indexValue", column="INDEX_VALUE"),
@Result(property="status", column="STATUS"),
@Result(property="lastUpdateTime", column="LAST_UPDATE_TIME")
})
List<Difference> getDifferencesByScanIDs(@Param("childScanIDs") String childScanIDs);
Run Code Online (Sandbox Code Playgroud)
我正在以这种方式构造值字符串:
String scanIDs = StringUtils.join(cmp.getChildScanIDs(), ",");
Run Code Online (Sandbox Code Playgroud)
执行该函数时,它会引发此异常。
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: ORA-01722: invalid number
### The error may involve com.rs2.automation.soacomparison.dao.differences.DifferencesMapper.getDifferencesByScanIDs-Inline
### The error occurred while setting parameters
### Cause: java.sql.SQLSyntaxErrorException: ORA-01722: invalid number
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。我认为问题在于 mybatis 没有将这些值识别为单独的数字。另一种解决方案是对每个数字执行查询,但我想一次传递所有值。提前致谢。
我遇到了一个看起来很小但我无法解决的问题。这可能很愚蠢,但我找不到任何解决方案。
我正在我的 PC 上使用 PHP 7.1 开发 Symfony 3 应用程序。一切正常。我尝试将其上传到使用 PHP 7.0 的主机服务器上。
当我启动网站时,我收到此错误消息:
致命错误:未捕获的类型错误:Doctrine\Common\Annotations\AnnotationRegistry::registerLoader() 的返回值必须是 Doctrine\Common\Annotations\void 的一个实例,在 /home/clients/fb3f5a508aeeb6d39e6d7e1e47bda9ac/vendor/doctrine 中没有返回lib/Doctrine/Common/Annotations/AnnotationRegistry.php:117 堆栈跟踪:#0 /home/clients/fb3f5a508aeeb6d39e6d7e1e47bda9ac/app/autoload.php(9): Doctrine\Common\Annotations\AnnotationRegistry::1Loader /(Array) home/clients/fb3f5a508aeeb6d39e6d7e1e47bda9ac/web/app.php(6): require('/home/clients/f...') #2 {main} 被扔到 /home/clients/fb3f5a508aeeb6d39e6d7e1e47bandinelib/docs/ /Doctrine/Common/Annotations/AnnotationRegistry.php 第 117 行
我发现那些链接似乎非常有用: - Symfony 致命错误 - http://www.doctrine-project.org/2017/07/25/php-7.1-requirement-and-composer.html
但是,我无法解决问题。我找不到我需要与 PHP 7.0 兼容的版本...
在我的 Composer json 配置文件中,我有:
"platform": {
"php": "7.0"
},
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"misd/phone-number-bundle": "^1.2",
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"symfony/monolog-bundle": "^3.0.2",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.3.10",
"symfony/symfony": "3.3.*",
"twig/twig": …Run Code Online (Sandbox Code Playgroud) 为了好玩,我正在尝试编写一个使用带有另一个注释的注释的类,但我不明白如何编码。
@interface FirstAnnotation {
String author();
}
Run Code Online (Sandbox Code Playgroud)
public @interface SecondAnnotation {
FirstAnnotation inside();
int version();
}
Run Code Online (Sandbox Code Playgroud)
@FirstAnnotation(
author = "alessandro"
)
@SecondAnnotation(
version = 1,
inside = /*Compilation code: what code? FirstAnnotation, this??*/
)
public class GeneralClass {
/*
* a generic method
*/
public void method() {
System.out.println("method");
}
}
Run Code Online (Sandbox Code Playgroud)
我必须在带有字符串编译代码的行中放入什么,作为类中FirstAnnotation实际值的参考?
我正在使用 PDFKIT 在 pdf 上画一条线。我覆盖触摸开始,移动等如下记录我在pdfView的documentView上的触摸如下:
override func touchesMoved(_ touches: Set<UITouch>,
with event: UIEvent?) {
// 6
swiped = true
if let touch = touches.first {
let currentPoint = touch.location(in: pdfView.documentView)
drawLineFrom(fromPoint: lastPoint, toPoint: currentPoint)
addAnnotation(fromPoint: lastPoint, toPoint: currentPoint)
// 7
lastPoint = currentPoint
}
}
Run Code Online (Sandbox Code Playgroud)
但是,正如您从下面的图片中看到的(黑线是我触摸屏幕的位置,红线是绘制注释的位置)。触摸坐标系是屏幕左上角的 (0,0),而 pdf 是从屏幕左下角 (0,0) 注释的。
我的添加注解功能如下:
func addAnnotation(fromPoint: CGPoint, toPoint: CGPoint) {
let page = pdfView.document?.page(at: 0)
let bounds = CGRect(x: 0, y: 0, width: 600, height: 600)
let line = PDFAnnotation(bounds: bounds, forType: …Run Code Online (Sandbox Code Playgroud) 我正在构建一个 web 应用程序,Symfony因为现在我不得不为我构建的每个新控制器重复一个特定的模式。
例如我有这个AdminController:
/**
* @Route("/pro/{uniqid}")
* @ParamConverter("company", options={"mapping":{"uniqid" = "uniqid"}})
* @Security("is_granted(constant('App\\Security\\Voter\\CompanyVoter::VIEW'), company)")
* @package App\Controller
*/
class AdminController extends Controller
{
/**
* @Route("/admin/users/", name="users")
* @return \Symfony\Component\HttpFoundation\Response
*/
public function users(Company $company){}
}
Run Code Online (Sandbox Code Playgroud)
因此,每个控制器必须重新定义@Route,@ParamConverter而@Security这是非常多余。
我试图创建一个LoggedController定义每个注释的,然后 makeController扩展那个LoggedController,但这不起作用。
有没有解决方案,或者我应该在每次创建一个Controller需要实现它的新注解时继续复制/粘贴这些注解?
编辑:我添加Company实体声明:
/**
* @ORM\Entity(repositoryClass="App\Repository\CompanyRepository")
*/
class Company
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
Run Code Online (Sandbox Code Playgroud) 我像这样使用了java @Value,它工作正常,并且可以正确解析变量“baiduurl”:
package com.lanyyyy.springdemo.controllers;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.lanyyyy.springdemo.service.*;
@RestController
public class GetURL {
@Value("${baiduurl}")
public String baiduurl;
@RequestMapping(path="/getbaidu", method=RequestMethod.GET)
public String getBaiduurl(){
// return "hello";
return baiduurl;
}
}
Run Code Online (Sandbox Code Playgroud)
======================
但是当我这样使用时,变量“baiduurl”无法解析:
package com.lanyyyy.springdemo.service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
@PropertySource("classpath:application.properties")
public class UrlService {
@Value("${baiduurl}")
public String baiduurl;
// @RequestMapping(path="/getbaidu", method=RequestMethod.GET)
public String getBaiduurl() {
return baiduurl;
}
}
Run Code Online (Sandbox Code Playgroud)
有什么不对的吗?????或者我用错了@Value????
在我的 applicaiton.properties 中:
baiduurl=http://www.baidu.com
server.port=8888
Run Code Online (Sandbox Code Playgroud) 我试图简单地从属性文件中获取值,一个false像这样的布尔值 :
@PropertySource("classpath:/conf/default/server.properties")
........
@Value("${startup.notify.enabled}")
private boolean enabled;
Run Code Online (Sandbox Code Playgroud)
在属性文件中:
startup.notify.enabled=true
Run Code Online (Sandbox Code Playgroud)
为什么我收到这个错误?
Caused by: java.lang.IllegalArgumentException: Invalid boolean value [${startup.notify.enabled}]
at org.springframework.beans.propertyeditors.CustomBooleanEditor.setAsText(CustomBooleanEditor.java:123)
at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:464)
at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:437)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:195)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:125)
at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:61)
Run Code Online (Sandbox Code Playgroud)
这可能是因为占位符"${startup.notify.enabled}"吗?
annotations ×10
java ×6
php ×2
spring ×2
spring-boot ×2
symfony ×2
autowired ×1
database ×1
doctrine-orm ×1
ios ×1
mybatis ×1
oracle ×1
pdfkit ×1
spring-mvc ×1
swift ×1
symfony4 ×1
touch ×1