小编val*_*lik的帖子

组件共享数据时,无法读取未定义的值?

我无法使用从服务中调用getbyId()方法收到的数据填充表单,在我的控制台中我看到错误:无法读取未定义的truckId,我发现的每个解决方案都说我的表单已呈现比我想用getById()方法得到的对象更快,解决方案应该是*ngIf ="truck",它应该使表单等待,但它不解决它只是拒绝显示所有形式的表单.IN stackblitz https://stackblitz.com/edit/stackoverflow-49847806-kdjhdc?file=app%2Fservices%2Ftruck.service.ts

但在控制台中,我可以看到URL,当我打开它时,我发现它实际上从我的后端服务获得了详细信息

getTruckById(id: number): Observable<Truck> {
   const url = `${this.baseUrl}/${id}`;
    return this.http.get(url, {headers: this.headers})
      .pipe(map(this.extractData),
        tap(data => console.log(JSON.stringify(data))),
        catchError(this.handleError));
  } 
Run Code Online (Sandbox Code Playgroud)

这完全是编辑组件

export class EditTruckComponent implements OnInit {
  five : number = 5;
  seven: number = 7;

 @Input() truck: Truck;

  truckIdTOUpdate: number;
  processValidation = false;
  dates: string;
  statusCode: number;
  requestProcessing = false;

   truckForm = new FormGroup({
    truckCode: new FormControl(Validators.maxLength(this.seven), Validators.minLength(this.five)),
    date: new FormControl('', Validators.required  ),
    descriptions: new FormControl(Validators.maxLength(this.seven), Validators.minLength(this.five))
  });


  constructor( private route: ActivatedRoute, private truckService: …
Run Code Online (Sandbox Code Playgroud)

javascript angular

13
推荐指数
1
解决办法
270
查看次数

为什么我不能将@WithMockUser导入我的测试

我正在尝试使用@With Mock User进行身份验证测试,但它拒绝在spring boot中导入我的测试类.这是类配置

@WebAppConfiguration
@AutoConfigureMockMvc
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = AdminPortalApplication.class)
public class BookControllerTest {
Run Code Online (Sandbox Code Playgroud)

@WithMockUser无法导入,它的红色显示弹簧启动无法识别它,我使用了这个依赖和属性

<spring-security.version>4.0.2.RELEASE</spring-security.version>


       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

保持说无法解析符号@WithMockUser

spring-boot

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

重定向 URL = http://localhost/login 在需要身份验证的控制器方法中

我正在测试需要身份验证的控制器,我已尽我所知执行了身份验证,但我仍然不断重定向,调试后它显示登录有效,所以我不明白为什么它继续在下面显示

Redirected URL = http://localhost/login
          Cookies = []

java.lang.AssertionError: No ModelAndView found

    at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:35)
Run Code Online (Sandbox Code Playgroud)

这是 Spring Boot,这是我的测试和控制器方法。

  @RequestMapping("/bookDetail")
    public String bookDetail(
            @PathParam("id") Long id, Model model, Principal principal
    ) {
        if (principal != null) {
            String username = principal.getName();
            User user = userService.findByUsername(username);
            model.addAttribute("user", user);
        }

        Book book = bookService.findOne(id);

        model.addAttribute("book", book);

        List<Integer> qtyList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

        model.addAttribute("qtyList", qtyList);
        model.addAttribute("qty", 1);

        return "bookDetail";
    }
Run Code Online (Sandbox Code Playgroud)

并测试。

@Test
    public void checkBookDetail() throws Exception { …
Run Code Online (Sandbox Code Playgroud)

spring mocking spring-boot

6
推荐指数
0
解决办法
613
查看次数

使用HttpClient与Java客户端访问电源Bi组

我想使用ResteasyClient访问电源Bi中的组列表,身份验证的形式我想使用服务主体(仅应用程序令牌)。我有应用程序ID(客户端),应用程序秘密(密钥)范围= Group.Read.All,访问令牌URL https://login.microsoftonline.com/common/oauth2/token和授予类型=客户端凭据。

public static String getAccessToken(OAuth2Details oauthDetails) {
    HttpPost post = new HttpPost(oauthDetails.getAuthenticationServerUrl());
        String clientId = oauthDetails.getClientId();
        String clientSecret = oauthDetails.getClientSecret();
        String scope = oauthDetails.getScope();

        List<BasicNameValuePair> parametersBody = new ArrayList<BasicNameValuePair>();
        parametersBody.add(new BasicNameValuePair(OAuthConstants.GRANT_TYPE,
                oauthDetails.getGrantType()));

        parametersBody.add(new BasicNameValuePair(OAuthConstants.CLIENT_ID,
                clientId));

        parametersBody.add(new BasicNameValuePair(
                OAuthConstants.CLIENT_SECRET, clientSecret));

        if (isValid(scope)) {
            parametersBody.add(new BasicNameValuePair(OAuthConstants.SCOPE,
                    scope));
        }

        HttpClient client = new DefaultHttpClient();
        HttpResponse response = null;
        String accessToken = null;
        try {
            post.setEntity(new UrlEncodedFormEntity(parametersBody, HTTP.UTF_8));
            response = client.execute(post);
            int code = response.getStatusLine().getStatusCode();
            if (code == OAuthConstants.HTTP_UNAUTHORIZED) {
                if …
Run Code Online (Sandbox Code Playgroud)

java resteasy powerbi

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

我如何获得 Postgres 端口

我刚刚安装了 Postgres,我尝试检查它是否正在运行以及在哪个端口上运行,尽管我知道它通常具有的默认端口这些命令没有向我显示端口。

service postgresql status
Run Code Online (Sandbox Code Playgroud)

我明白了

postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor prese
   Active: active (exited) since Tue 2018-09-18 14:17:14 CEST; 22min ago
  Process: 2632 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 2632 (code=exited, status=0/SUCCESS)
    Tasks: 0
   Memory: 0B
      CPU: 0
   CGroup: /system.slice/postgresql.service

Sep 18 14:17:14 user-HP-Pavilion-TS-15-Notebook-PC systemd[1]: Starting PostgreS
Sep 18 14:17:14 user-HP-Pavilion-TS-15-Notebook-PC systemd[1]: Started PostgreSQ
Sep 18 14:39:19 user-HP-Pavilion-TS-15-Notebook-PC systemd[1]: Started PostgreSQ
Run Code Online (Sandbox Code Playgroud)

当我只是尝试简单地检查进程并查看它在命令后显示的端口时

 sudo netstat -plunt |grep postgres

tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      2592/postgres   
tcp        0 …
Run Code Online (Sandbox Code Playgroud)

postgresql

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

休眠映射异常无法确定类型:java.nio.file.Path

我有一个实体照片如下

@Entity
class Photo {

Path imagePath;

public Path getImagePath(){
return imagePath;
// setter
}
Run Code Online (Sandbox Code Playgroud)

在这个实体中,我必须使用 nio.Path 如何解决这个问题或使 db 中的表接受字符串作为路径错误堆栈在下面

Caused by: org.hibernate.MappingException: Could not determine type for: java.nio.file.Path, at table: photo, for columns: [org.hibernate.mapping.Column(image_path)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:431)
Run Code Online (Sandbox Code Playgroud)

java hibernate

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

测试一个简单的hello world方法

我在春季曾进行过junit测试集成测试和控制器测试,通常我们会测试方法的输出,但是当我尝试在main方法中测试一个简单的hello世界时,我不知道如何进行操作,因此希望获得任何方法关于写什么的想法

public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}
Run Code Online (Sandbox Code Playgroud)

这是简单的Java类,我知道如何测试它,我试图写这样的东西

public void mainMethodTest() throws Exception{

        System.out.println("hello world");
        String[] args = null;


        Assert.assertEquals(System.out.println("hello world"),App.main(args));
    }
Run Code Online (Sandbox Code Playgroud)

java

3
推荐指数
2
解决办法
499
查看次数

我如何处理服务类模拟的创建并进行测试?

当尝试测试时,当需要从下面的控制器中删除一个方法时,事情会变得很棘手

@RequestMapping(value="/remove", method=RequestMethod.POST)
public String remove(
        @ModelAttribute("id") String id, Model model
) {
    bookService.removeOne(Long.parseLong(id.substring(8)));
    List<Book> bookList = bookService.findAll();
    model.addAttribute("bookList", bookList);

    return "redirect:/book/bookList";
}
Run Code Online (Sandbox Code Playgroud)

我的测试从下面的之前测试方法中的模拟注入开始

@Before
public void setUp() {
    bookService = createMock(BookService.class);

    ReflectionTestUtils.setField(bookController, "bookService", bookService);

    userRepository= createMock(UserRepository.class);
    ReflectionTestUtils.setField(bookController, "userRepository", userRepository);

    mockMvc = standaloneSetup(bookController)
            .setMessageConverters(new MappingJackson2HttpMessageConverter())
            .build();
}
Run Code Online (Sandbox Code Playgroud)

最后是测试,尝试删除一本书,而不是让它写入。我该如何继续?

@Test
public void bookRemoveTest() throws Exception {
   securityService.autologin("admin", "admin");

    Book book = new Book();
    book.setId(1L);

    expect(bookService.removeOne(anyObject( class));).andReturn(book);

    replay(bookService);

    MvcResult result = mockMvc
            .perform(post("/book/remove")
                    .accept(MediaType.TEXT_HTML)
                    .contentType(MediaType.TEXT_HTML))
            .andExpect(status().isOk())
            .andReturn();
    String controllerResult = result.getResponse().getContentAsString();
 } …
Run Code Online (Sandbox Code Playgroud)

java unit-testing easymock mocking

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

如何解决OutOfMemoryError:Java堆空间

运行此代码时出现此错误

private static List<Integer> array(int num) {
       List<Integer> value = new ArrayList<>();

        while (num != 1) {
            if(num % 2 == 0) {
             value.add(num + 2);
             }else {
              value.add(num * 3 + 1);
             }
        }
       System.out.println(value);
        return value;
    }
Run Code Online (Sandbox Code Playgroud)

我能得到什么错的解释吗?

java

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