小编Rob*_*rto的帖子

使用hibernate-envers时,AUD表中的所有@Version字段都为null,但是在实体 - 表填充的okey中?

应用程序spring + jpa + envers(hibernate)envers需要在特殊表中保存实体的历史记录.

在我保存了几次实体之后,我希望在USER表中看到填充版本字段,在USER_AUT中看到填充版本字段.但实际的结果是user表中正确的值,但在版本colums添加REV_TYPE,REV列(在现场只是种台的所有行)和空.

我使用4.0.1.Final hibernate

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-envers</artifactId>
    <version>4.0.1.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.0.1.Final</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

但是,当我查看表时,Version字段中的所有值都为null

我的实体是

import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.envers.Audited;

import javax.persistence.*;

@Entity
@Audited
@Table(name = "User", uniqueConstraints = {
        @UniqueConstraint(columnNames = { "prKey"})})
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor
@Getter
@Setter
public class User {
    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(name = "PR_KEY", unique = true)
    private String prKey;

    @Column(name = "name", length = 100, unique = false)
    private String …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa hibernate-envers

10
推荐指数
1
解决办法
456
查看次数

如何在 Spring 中为单元测试创​​建 HttpServletResponse?

如何HttpServletResponse为单元测试创建,我可以在其中编写输出流和标头(不是MockHttpServletResponse)?在 assert 块中,我希望将OutputStream标头与标准具进行比较httpServletResponse

我用过Spring4java8EasyMocklib。

java spring easymock

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

如何通过reactjs在图标下创建带有文本的按钮?

现在,我有这样的组件: 在此处输入图片说明

它的代码:

import React from "react";
import {withStyles} from "material-ui/styles";
import Settings from "material-ui-icons/Settings"; 
import Button from "material-ui/Button";

const styles = {
button: {
    color: "primary",
    height: 95,
    width: 95,
    disableRipple: "true",
    focusRipple: "true",
},
icon: {
    height: 35,
    width: 35,
    display: "block",
    float: "none",
},
text: {
    height: 35,
    width: 35,
    display: "block",
    float: "none",
    marginTop: 10,
},
};

/* eslint-disable react/prop-types */
const IconedLabel = ({classes}) => (
<section>
    <Button className={classes.iconButton} variant="raised" color="primary">
        <Settings className={classes.icon}/>
        <div className={classes.text}>Message</div>
    </Button> …
Run Code Online (Sandbox Code Playgroud)

javascript css reactjs material-ui

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

如何在没有&lt;br&gt;的情况下使版式材料成为用户界面

默认的Typography材质-ui在新行上移动下一个tag-element,当下一个fe在此行时,如何自定义此组件?

我使用这个组件。

reactjs material-ui

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

尝试在 websphere 8.5.5.13 上部署 ear 时出现 AnnotationException?

spring 4.13 上有应用程序 所以,当尝试在 websphere 8.5.5.13 上部署 ear-file 时 - 有错误消息

[12/18/18 14:56:41:946 MSK] 00000086 AnnotationCon E CWMDF0002E:注释处理失败,错误如下:com.ibm.ws.metadata.annotations.AnnotationException:类的注释处理失败:META-INF/版本/9/javax/xml/bind/ModuleUtil.class

这是一个什么样的问题?这可能是应用程序和服务器库的安装错误或错误不兼容?

应用程序有入口点

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"spring"})
public class WebAppInitalizer implements WebApplicationInitializer {
    private static final String CONFIG_LOCATION = "spring.config";
    private static final String MAPPING_URL = "/*";

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>> ONSTARTUP <<<<<<<<<<<<<<<<<<<<<<<<");
        WebApplicationContext context = getContext();
        servletContext.addListener(new ContextLoaderListener(context));
        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping(MAPPING_URL);
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>> ONSTARTUP END <<<<<<<<<<<<<<<<<<<<<<<<");
    }

    private AnnotationConfigWebApplicationContext getContext() {
        AnnotationConfigWebApplicationContext …
Run Code Online (Sandbox Code Playgroud)

java websphere spring

6
推荐指数
2
解决办法
5523
查看次数

在React + Redux代码中,TypeError(0,_ColorReducer.color)不是函数错误

我尝试从React&Redux第204页的书中实现示例,但是,有一个奇怪的问题 - There is TypeError (0 , _ColorReducer.color) is not a function error in React code

我有2个减速器用于一种颜色和颜色数组:

import React from "react";
import * as C from "./Constants";
import { color } from "./ColorReducer";

export const colorsReducer = (state = [], action) => {
  switch (action.type) {
    case C.ADD_COLOR:
      return [...state, color({}, action)];
    case C.RATE_COLOR:
      return state.map(item => color(item, action));
    default:
      return state;
  }
};
Run Code Online (Sandbox Code Playgroud)

import React from "react";
import * as c from "./Constants";

export const ?olor = (state …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs redux

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

spring-boot 上的集成测试抛出连接被拒绝

我对 Spring Boot 进行了单元测试:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class CustomerControllerIT {
    private RestTemplate restTemplate = new RestTemplate();
    @Test
    public void findAllCustomers() throws Exception {
        ResponseEntity<List<Customer>> responseEntity = restTemplate.exchange(
                "http://localhost:8080/Customer", HttpMethod.GET, null,
                new ParameterizedTypeReference<List<Customer>>() {
                });
        List<Customer> list = responseEntity.getBody();
        Assert.assertEquals(list.size(), 0);
    }
}
Run Code Online (Sandbox Code Playgroud)
  • 如果我在启动的应用程序上启动测试 - 测试正常

  • 如果我尝试仅启动 IT,则会出现连接被拒绝的错误

application.properties的单启动是一样的。

用于测试并位于资源和测试资源中。

Application.class 是:

@ComponentScan({"mypackage"})
@EntityScan(basePackages = {"mypackage.model"})
@EnableJpaRepositories(basePackages = {"mypackage.persistence"})
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

integration-testing spring-boot

5
推荐指数
2
解决办法
5335
查看次数

Spring Rest 控制器从查询参数中的 zonedatetime 中删除加号

我有UT,顺利通过

    @Test
    public void test() {
        String text1 = "2009-07-10T14:30:01.001Z";
        String text2 = "2009-07-10T14:30:01.001+03:00";
        DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ");

        ZonedDateTime zonedDateTime1 = ZonedDateTime.parse(text1, f);
        ZonedDateTime zonedDateTime2 = ZonedDateTime.parse(text2, f);

        System.out.println(zonedDateTime1);
        System.out.println(zonedDateTime2);
    }
Run Code Online (Sandbox Code Playgroud)

输出是

2009-07-10T14:30:01.001Z
2009-07-10T14:30:01.001+03:00
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试在 spring-controller 上使用这种模式时

    @GetMapping
    public ResponseEntity get( @RequestParam("start") @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ")
                                               ZonedDateTime start) {
        Dto result = service.get(start);
        return new ResponseEntity(result, getHeaders(), HttpStatus.OK);
    }
Run Code Online (Sandbox Code Playgroud)

例如,仅当我传递 Z 而不是时区时,它才有效

2009-07-10T14:30:01.001Z
Run Code Online (Sandbox Code Playgroud)

但是当尝试传递时区偏移时 - 出现错误消息

“无法将类型“java.lang.String”的值转换为所需类型“java.time.ZonedDateTime”;嵌套异常为 org.springframework.core.convert.ConversionFailedException:无法从类型 [java.lang.String] 转换输入 [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.time.ZonedDateTime] 获取值 '2009-07-10T14:30:01.001 03:00';嵌套异常是 java.lang.IllegalArgumentException:解析尝试失败的值 [2009-07-10T14:30:01.001 03:00]”,

我尝试像这样通过邮递员传递请求

POST …
Run Code Online (Sandbox Code Playgroud)

java controller spring-boot zoneddatetime

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

如何从控制台删除警告?

使用了 redux、react 和material-ui lib \n我有使用react 和redux 的react 组件。从 redux 接收到的状态,因此,\n此组件:

\n\n
import React from "react";\nimport {withStyles} from "material-ui/styles";\nimport {MenuItem} from "material-ui/Menu";\nimport Chip from "material-ui/Chip";\nimport CancelIcon from "@material-ui/icons/Cancel";\nimport Input from "material-ui/Input";\nimport Select from "react-select";\nimport Typography from "material-ui/Typography";\n\nconst ITEM_HEIGHT = 48;\n\nconst styles = theme => ({\n  // Autocomplete styles\n  "@global": {\n    ".Select-control": {\n      display: "flex",\n      alignItems: "center",\n      border: 0,\n      height: "auto",\n      background: "transparent",\n      "&:hover": {\n        boxShadow: "none",\n      },\n    },\n    ".Select-multi-value-wrapper": {\n      flexGrow: 1,\n      display: "flex",\n      flexWrap: "wrap",\n    },\n    ".Select--multi .Select-input": {\n …
Run Code Online (Sandbox Code Playgroud)

reactjs redux

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

为什么onClick无法在自定义组件中起作用?

我有两个组件StarStarRating((尝试实现来自React和Redux的书中的示例,第135页)。因此,我想渲染任何星星并在单击一颗星星时执行一些操作。因此,我尝试添加console.logonClick,但是没有用。您能帮我修复代码并解释为什么它不起作用吗?

StarRating.js

import React from "react";
import Star from "./Star";
import { Component } from "react";

class StarRating extends Component {
  displayName: "star-rating";

  constructor(props) {
    super(props);
    this.state = {
      totalStars: 5,
      starsSelected: 2
    };
    this.change = this.change.bind(this);
  }

  change(starsSelected) {
    console.log(starsSelected);
    this.setState({ starsSelected });
  }

  render() {
    const  totalStars  = 5;
    const { starsSelected } = this.state;
    console.log({ totalStars });
    return (
      <div className="star-rating">
        {[...Array(totalStars)].map((n, i) => {
          return (
            <Star
              key={i} …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

如何从 jpa-repository 更改方法名称?

spring+jpa(repositories) 实体有应用:

@Entity
@Getter
@Setter
@NoArgsConstructor
public class User{
  private int id;
  private String name;
  private String surname;
  private int age;
}
Run Code Online (Sandbox Code Playgroud)

因此,我的存储库如下所示:

@Repository
public interface UserRepository extends CrudRepository<User, Integer>{
  public List<User> findUsersByNameAndAge(String name, int age);
  public List<User> findUsersByNameAndSurname(String name, String surname);
}
Run Code Online (Sandbox Code Playgroud)

在我真正的生产代码中,参数太多,所以这个方法名太长而且不舒服。有没有办法从长方法名称中创建舒适的选项,例如仅查找?

spring repository spring-data-jpa

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