小编Cat*_*t H的帖子

如何修复Uncaught TypeError:无法读取未定义的属性'prototype'?

我有一点问题.我正在使用backbone.js.我在例子中编写了这段代码:

<script>
$(document).ready(function () {
    window.App = {
        Views: {},
        Models: {},
        Collections: {}
    }

    App.Collections.Users = Backbone.Collection.extend({
         model: App.Models.User,
         url: 'service'
    });
    App.Models.User = Backbone.Model.extend({});

    App.Views.App = Backbone.View.extend({
         initialize: function() {
             console.log( this.collection.toJSON() );
         }
    });

});
</script>
Run Code Online (Sandbox Code Playgroud)

比我启动服务器和浏览器控制台键入:

var x =new App.Collections.Users();
x.fetch()
Run Code Online (Sandbox Code Playgroud)

这跟随错误:Uncaught TypeError: Cannot read property 'prototype' of undefined.但数据存在作为回应.图片详情.如何解决这个问题?谢谢你的回答.在此输入图像描述

在此输入图像描述

javascript jquery backbone.js

36
推荐指数
2
解决办法
8万
查看次数

REST客户端restTemplate无法获取对象集合

我使用Spring restTemplate.我在单独的应用程序中将REST服务和客户端作为单元测试.我有返回用户列表的方法和用户创建方法:

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON,
        MediaType.TEXT_XML })
@Path("/all")
public Response getAllUsers() {
    List<User> list = dao.getAll();
    GenericEntity<List<User>> result = new GenericEntity<List<User>>(list) {
    };
    return Response.status(Status.OK).entity(result).build();
}
Run Code Online (Sandbox Code Playgroud)

如果我要求在浏览器中向我显示所有用户,它会向我显示xml.没关系.但是,当我尝试使用它时:

@Test
public void testGetAll() {
    List list = new RestTemplate().getForObject(URL + "all", List.class);
    System.out.println(list);
}
Run Code Online (Sandbox Code Playgroud)

我有

WARNING: GET request for "http://localhost:8080/REST/all" resulted in 500 (Internal Server Error); invoking error handler
Run Code Online (Sandbox Code Playgroud)

我试着调试这个.方法工作期间没有例外.浏览器向我展示了用户的xml.有什么不对?

另外,我想知道,如何从模板对象中获取状态代码或消息(用于测试)?

谢谢你的回答.

编辑:

我修改了我的测试方法:

@Test
public void testGetAll() {
    RestTemplate template = new RestTemplate();

    List<HttpMessageConverter<?>> messageConverters = new    ArrayList<HttpMessageConverter<?>>();
    Jaxb2RootElementHttpMessageConverter jaxbMessageConverter …
Run Code Online (Sandbox Code Playgroud)

java collections rest spring resttemplate

30
推荐指数
4
解决办法
6万
查看次数

无法自动装配字段:private org.springframework.security.authentication.AuthenticationManager

我正在尝试使用本教程Spring OAuth2创建OAuth2服务器提供程序.示例和我的项目之间的主要区别 - 我不使用Spring Boot.我尝试拆分这个类(GitHub示例链接)我创建了2个类:

@Configuration
@Order(-20)
@EnableResourceServer
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

  @Autowired
  private AuthenticationManager authenticationManager;

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.formLogin().loginPage("/login").permitAll()
            .and()
            .requestMatchers().antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access")
            .and()
            .authorizeRequests().anyRequest().authenticated();
  }

  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.parentAuthenticationManager(authenticationManager);
  }
Run Code Online (Sandbox Code Playgroud)

}

二等:

@Configuration
@EnableAuthorizationServer
@EnableResourceServer
public class OAuth2AuthorizationConfiguration extends AuthorizationServerConfigurerAdapter {

  @Autowired
  private AuthenticationManager authenticationManager;

  @Bean
  public JwtAccessTokenConverter jwtAccessTokenConverter() {
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    KeyPair keyPair = new KeyStoreKeyFactory(
            new ClassPathResource("keystore.jks"), …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security spring-boot

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

Spring MVC将属性设置为request/model/modelMap

我使用Spring MVC.我需要为请求或其他对象添加属性.它应该是将在屏幕上显示的消息.例如,如果我使用纯Servlet,我可能只是:

request.setAttribute("message", "User deleted");
Run Code Online (Sandbox Code Playgroud)

而不是在JSP页面上

<div id="message">${message}</div>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试在方法中做这样的事情时:

@RequestMapping(value = "/delete", method = RequestMethod.GET)
public String deleteUser(@RequestParam("login") String login,
        ModelMap map, HttpServletRequest request)
Run Code Online (Sandbox Code Playgroud)

模型对象 -

model.addAttribute("message", "User deleted");
Run Code Online (Sandbox Code Playgroud)

地图 -

map.put("message", "User deleted");
Run Code Online (Sandbox Code Playgroud)

模型地图 -

map.put("message", "User deleted");
Run Code Online (Sandbox Code Playgroud)

HttpServletRequest -

request.setAttribute("message", "User deleted");
Run Code Online (Sandbox Code Playgroud)

没有显示.但在我的浏览器中我看到:http:// localhost:8081/project/index?message = User + deleted

如何解决这个小问题?谢谢你的回答

更新:

为了清楚地理解我试着这样做:

 @RequestMapping(value = "/delete", method = RequestMethod.GET)
public String deleteUser(@RequestParam("login") String login,
        Model model) {
    dao.delete(login); // there is NO exeptions
    map.addAttribute("message", "User " + login + " …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc

15
推荐指数
2
解决办法
7万
查看次数

需要身份验证才能获取访问令牌(匿名不允许)

我尝试修改现有的示例 - Tonr2和Sparklr2.我还根据Spring Boot Spring Boot OAuth2查看了本教程.我尝试在Tonr2示例中构建应用程序但没有首次登录(在tonr2上).我只需要在Sparklr2端进行一次身份验证.我这样做:

@Bean
    public OAuth2ProtectedResourceDetails sparklr() {
        AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
        details.setId("sparklr/tonr");
        details.setClientId("tonr");
        details.setTokenName("oauth_token");
        details.setClientSecret("secret");
        details.setAccessTokenUri(accessTokenUri);
        details.setUserAuthorizationUri(userAuthorizationUri);
        details.setScope(Arrays.asList("openid"));
        details.setGrantType("client_credentials");
        details.setAuthenticationScheme(AuthenticationScheme.none);
        details.setClientAuthenticationScheme(AuthenticationScheme.none);
        return details;
    }
Run Code Online (Sandbox Code Playgroud)

但我有Authentication is required to obtain an access token (anonymous not allowed).我查了这个问题.当然,我的用户是匿名的 - 我想登录Sparklr2.此外,我尝试了这种bean的不同设置组合,但没有什么好处.怎么解决?如何使它按我想要的方式工作?

java spring spring-mvc spring-security spring-oauth2

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

Spring Data JPA - 如何通过孩子 ID 获取父母?

我有带有@ManyToMany 注释的父和子实体:

@Entity
@Table(name = "parent")
public class Parent {

    @Id
    @GenericGenerator(name = "uuid-gen", strategy = "uuid2")
    @GeneratedValue(generator = "uuid-gen",strategy=GenerationType.IDENTITY)
    private String id;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "parents_childs",
        joinColumns = {@JoinColumn(name = "parent_id", nullable = false, updatable = false)},
        inverseJoinColumns = {@JoinColumn(name = "child_id", nullable = false, updatable = false)})
    private List<Child> childs;
}
Run Code Online (Sandbox Code Playgroud)

和子实体:

@Entity
@Table(name="child")
public class Child {

    @Id
    @GenericGenerator(name = "uuid-gen", strategy = "uuid2")
    @GeneratedValue(generator = "uuid-gen",strategy=GenerationType.IDENTITY)
    private String id;

}
Run Code Online (Sandbox Code Playgroud)

我的任务是查找包含具有特定 ID 的 Child …

java spring jpa

7
推荐指数
1
解决办法
7546
查看次数

如何从Java代码中清除Couchbase存储桶?

我需要每次在单元测试运行之前清除Couchbase存储桶.我使用Java SDK> 2.0版本.在以前的版本中,我发现了这个很棒的方法http://www.couchbase.com/autodocs/couchbase-java-client-1.1.1/com/couchbase/client/ClusterManager.html#flushBucket(java.lang.String)但是它在新版本中不存在.

有没有办法从桶中清除数据?我可以通过获取文档的所有键然后删除它们来删除,但我想使用更漂亮的方式.

java couchbase

6
推荐指数
1
解决办法
1517
查看次数

如何使用phantomjs?

我想学习phantomjs,但我找不到好的教程.我有两个问题:

  1. 以下代码中的问题在哪里(需要捕获按钮的标签并写入文件):

    var page = require('webpage').create();
    var fs = require('fs');
    
    page.onConsoleMessage = function(msg) {
        phantom.outputEncoding = "utf-8";
        console.log(msg);
    };
    
    page.open("http://vk.com", function(status) {
        if ( status === "success" ) {
            page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
                page.evaluate(function() {
                    var str = $("#quick_login_button").text();
                    f = fs.open("ololo.txt", "w");
                    f.writeLine(str);
                    f.close();
                    console.log("done");
                });
                phantom.exit();
            });
        }
    });
    
    Run Code Online (Sandbox Code Playgroud)
  2. 您可以向我建议使用phantomjs中的哪些教程?(不是来自官方网站)

phantomjs

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

JPA 规范搜索字符串列表包含

我有以下实体:

@Entity
@Table(name = "my_entity");
public class MyEntity {
    // some fields
    @Column(name = "languages")
    @Convert(converter = StringToListConverter.class)
    private List<String> languages;
}
Run Code Online (Sandbox Code Playgroud)

SQL表:

CREATE TABLE my_entity (
    id VARCHAR(255) PRIMARY KEY,
    // some fields
    languages VARCHAR(255) DEFAULT NULL
);
Run Code Online (Sandbox Code Playgroud)

该字段languages包含以逗号分隔的值列表EN,FR,NO

我的任务是选择包含某种语言的记录。例如,在本机 SQL 中我想使用以下 SQL:

SELECT * FROM my_entity e WHERE e.languages LIKE CONCAT('%', 'EN', '%');
Run Code Online (Sandbox Code Playgroud)

我尝试使用规范来做到这一点:

Specification<MyEntity> specification = (root, query, cb) -> {
    final Path<Collection<String>> langs = root.get("languages");
    // also I tried root.joinList
    return cb.isMember("EN", langs); …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa

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

NoSuchBeanDefinitionException如何初始化SessionFactory bean?

我有个问题.我尝试使用Spring和Hibernate运行我的Web应用程序/我有一个奇怪的错误.NoSuchBeanDefinitionException.Stacktrace是:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:967)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:837)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:749)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
Run Code Online (Sandbox Code Playgroud)

我不知道为什么,因为在我的servlet-context.xml中我声明了SessionFacory bean:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

<context:component-scan base-package="com.example" />
<context:component-scan base-package="com.example.service" />
<context:component-scan base-package="com.example.service.impl" />
<context:component-scan base-package="com.example.dao" />
<context:component-scan base-package="com.example.dao.impl.hibernate" />
<context:component-scan base-package="com.example.web.controller" />
<context:component-scan base-package="com.example.entity" />

<mvc:annotation-driven />

<tx:annotation-driven />

<bean …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate spring-mvc sessionfactory

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

选择表行时启用“ JSF Primefaces设置”按钮

我在一个表中有一个用户列表,并且禁用了“删除”按钮。选择表中的行时,需要启用“删除”按钮。我怎样才能做到这一点?

<p:dataTable value="#{userBean.patients}" var="item"
            selectionMode="single" rowKey="#{item.id}"
            selection="#{userBean.selected}"
onRowSelected="deleteButton.disabled='false';"> // HOW TO WRITE THIS EVENT CORRECTLY?????
// columns
</p:dataTable>
//This button must be enable after I click on any table row
<p:commandButton id="deleteButton" value="Delete" disabled="true" />
Run Code Online (Sandbox Code Playgroud)

也许,我需要使用onRowClick事件。我不知道这个活动的名字

javascript jsf primefaces

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

将int [] []的RGB保存为图像文件

我有图像的RBG值的数组int [] [],我需要将它存储到jpg文件.我试着这样做:

 BufferedImage image = ImageIO.read(new ByteArrayInputStream(result));
 ImageIO.write(image, "jpg", new File("/path/", "snap.jpg"));
Run Code Online (Sandbox Code Playgroud)

但我有一个int [] []不是byte []数组.如何将int [] []转换为byte []而不会丢失值?

java rgb bufferedimage image

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

导入 Maven 模块中的 Lombok

我有以下 Maven 结构:

parent-module
|-model-module
|-model-contributor-module
Run Code Online (Sandbox Code Playgroud)

model-module我有用 注释的实体@lombok.Data。当我穿上mvn clean install一切都好model-module。第二个内部模块model-contributor-module包含model-module依赖项。当我尝试执行相同的构建时model-contributor-module,我收到错误cannot find symbol

pom.xml为了model-module

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

对于:pom.xmlmodel-contributor-module

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
</dependency>
.....
<pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-maven-plugin</artifactId>
                <version>1.16.8.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
....
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-maven-plugin</artifactId>
            <version>1.16.8.0</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>testDelombok</goal>
                        <goal>delombok</goal>
                    </goals> …
Run Code Online (Sandbox Code Playgroud)

java maven lombok

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