标签: annotations

使用Annotation保护Symfony2 Controller的操作免受未经授权的请求

Controller's Action当用户未使用自定义注释登录时,我似乎无法确定是否可以保护.

这就是我想要实现的目标:

...
class FooController extends Controller
{
    ...

    /*
    * The code bellow should only be executed if the user 
    * is authorized, otherwise should throw an exception 
    * or something.
    *
    * @Authorized
    */
    public function barAction($cid) {
        // do stuff only if user is authorized
    }

    ...
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用某种" 装饰器设计模式 " 来做到这一点,但我真正想要的是更像Python的使用PHP 注释装饰器

这是真的吗?我该怎么办?

php python annotations decorator symfony

0
推荐指数
1
解决办法
503
查看次数

mappedBy引用一个未知的目标实体属性 - hibernate错误maven注释

我正在研究一个测试项目来学习hibernate,不幸的是我收到了这个错误,并查看了其他类似的错误,但是关注它们并没有解决我的问题.我仍然收到此错误.

有人可以检查出了什么问题,我真的很想知道我的错误是什么.

我的模型类:

@Entity
@Table(name="survey")
public class Survey implements java.io.Serializable{

    /**
    * 
    */
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
@Column(name = "survey_id")
private Long _id;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "survey")
private List<Question> _questions ;

@Column(name="name")
private String _name;

public Survey() {
    super();
}

public Survey(Long id, List<Question> questions, String name) {
    super();
    _id = id;
    _questions = questions;
    _name = name;

    Assert.notNull(_id, "_id cannot be null");
    Assert.notNull(_questions, "_questions cannot be null");
    Assert.notNull(_name, "_name cannot be null"); …
Run Code Online (Sandbox Code Playgroud)

java annotations hibernate

0
推荐指数
1
解决办法
3507
查看次数

两个@RequestMapping注释之间的差异

我是Spring MVC的新手,我有以下疑问.

在控制器中,我有一个以这种方式注释的方法:

@Controller
@RequestMapping(value = "/users")
public class UserController {

    @RequestMapping(params = "register")
    public String createForm(Model model) {
        model.addAttribute("user", new Customer());
        return "user/register";
    } 

}
Run Code Online (Sandbox Code Playgroud)

所以这个方法处理HTTP请求到URL / users?寄存器,其中register是一个参数(因为整个类处理对/ users资源的请求).

如果使用params ="register"我使用以下的syntaxt 是同样的事情:

@Controller
public class UserController {

    @RequestMapping("/users/{register}")
    public String createForm(Model model) {
        model.addAttribute("user", new Customer());
        return "user/register";
    } 

}
Run Code Online (Sandbox Code Playgroud)

我已经删除了类级别的映射,并使用了@RequestMapping("/ users/{register}").

它与第一个例子的含义相同吗?

java spring annotations spring-mvc request-mapping

0
推荐指数
1
解决办法
2225
查看次数

注释方法可以接受参数吗?

我很少编写注释,但它在java框架中使用得很好.

我有调查注释源,我有一个问题

我看到的所有注释方法都不接受参数.

例子(来自spring-mvc):

@Target({TYPE, FIELD, METHOD})
@Retention(RUNTIME)
public @interface Resource {
    /**
     * The JNDI name of the resource.  For field annotations,
     * the default is the field name.  For method annotations,
     * the default is the JavaBeans property name corresponding
     * to the method.  For class annotations, there is no default
     * and this must be specified.
     */
    String name() default "";

    /**
     * The name of the resource that the reference points to. It can
     * link …
Run Code Online (Sandbox Code Playgroud)

java annotations

0
推荐指数
1
解决办法
56
查看次数

Spring注释@Profile不允许此位置

我有一个配置文件,我想根据配置文件创建不同的bean.

出于某种原因,这是有效的:

@Configuration
@Profile("myProfile")
public class myClass {
Run Code Online (Sandbox Code Playgroud)

这不是,在Eclipse中给出错误消息:

@Profile此位置不允许使用注释

@Bean
@Profile("myProfile")
Run Code Online (Sandbox Code Playgroud)

我宁愿使用第二个,但我不确定我是否可以.Spring API说它应该工作:

@Profile注释可以在以下任一方式使用:

  • 作为直接或间接注释的任何类的类型级注释@Component,包括@Configuration
  • 作为元注释,用于组成自定义构造型注释
  • 作为任何@Bean方法的方法级注释

我正在使用Sping Framework 3.1.0,是否有可能@Bean仅在使用on 方法之后?

java spring annotations

0
推荐指数
1
解决办法
2086
查看次数

在Spring中实现JpaRepostiory时使用存储库注释

我不确定我是否理解正确,所以要澄清一下.如果我想为我的实体创建一个存储库,例如:

public interface BookRepository extends JpaRepository<Book, Id> {}
Run Code Online (Sandbox Code Playgroud)

我应该用@Repository注释它吗?根据这个问题, @ Repository注释将SQL中的异常转换为持久性,但JpaRepostiory是否已经这样做了?什么是最佳实践 - 注释与否?

java spring annotations spring-data-jpa

0
推荐指数
1
解决办法
1921
查看次数

运行python 3代码时出现python 2语法错误

我有一个如下所示的课程

class ExperimentResult(BaseDataObject):
    def __init__(self, result_type: str, data: dict, references: list):
        super().__init__()
        self.type = result_type
        self.references = references
        self.data = data

    def __repr__(self):
        return str(self.__dict__)
Run Code Online (Sandbox Code Playgroud)

代码是用python 3编写的,而我正在尝试在python 2中运行它.当我运行它时,我得到了

    def __init__(self, result_type: str, data: dict, references: list):
                                  ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

是否有"import_from_future"来解决这个问题?

python annotations type-hinting python-2.7 python-3.x

0
推荐指数
1
解决办法
927
查看次数

PDFKit iOS 11:如何更改Ink注释的线宽?

我正在使用PDFKit在PDF文件上绘制一些墨迹注释.但我无法改变线条的宽度.我以为这样做:

let path = UIBezierPath()
path.lineWidth = 20 // important line
path.move(to: originPoint)
path.addLine(...)
annotation.add(path)
Run Code Online (Sandbox Code Playgroud)

因为在Core Graphics中绘制时修改Bezier路径的lineWidth是可行的.但是在这里,它没有改变任何东西,那么如何改变注释的线宽?

annotations pdfkit ios swift

0
推荐指数
1
解决办法
754
查看次数

函数参数dtype声明不起作用?

为什么这不回馈'12'?
'+'符号应该连接两个字符串,而不是添加它们.

def foo(a:str, b:str):
    print(a+b)
foo(1,2)
3
Run Code Online (Sandbox Code Playgroud)

python annotations function python-3.x

0
推荐指数
1
解决办法
80
查看次数

创建遗留类的Bean,无需修改且无需xml配置

我有一些现有的旧式帮助程序类,没有bean注释,也没有xml配置。我想为相同的类创建bean,而无需修改(不添加注释),并且在xml中没有任何额外的配置。可能吗?

java spring annotations data-annotations spring-boot

0
推荐指数
1
解决办法
50
查看次数