Java 为什么我的vaadin按钮显示不正确?

Java 为什么我的vaadin按钮显示不正确?,java,spring-boot,kotlin,vaadin,vaadin-flow,Java,Spring Boot,Kotlin,Vaadin,Vaadin Flow,差不多就是这个标题,我到处寻找答案,但我要么错过了设置中的一些东西,spring错过了,gradle f'ed up错过了,要么我看不懂 我认为我的页面应该是一个漂亮的蓝色按钮或其他东西(我知道我删除了网格),我遵循了,但我得到的是我的build.gradle和相关代码: build.gradle: plugins { id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.21' id 'org.springframework.boo

差不多就是这个标题,我到处寻找答案,但我要么错过了设置中的一些东西,spring错过了,gradle f'ed up错过了,要么我看不懂

我认为我的页面应该是一个漂亮的蓝色按钮或其他东西(我知道我删除了网格),我遵循了,但我得到的是我的build.gradle和相关代码:

build.gradle:

plugins {
    id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.21'
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'org.jetbrains.kotlin.jvm' version '1.3.21'
    id 'org.jetbrains.kotlin.plugin.spring' version '1.3.21'
    id 'com.devsoap.vaadin-flow' version '1.0'
    //id 'org.gretty' version '2.3.1'
    id 'java'
    // solves the problem with long classpath using JAR instead of classpath on command line
    id "ua.eshepelyuk.ManifestClasspath" version "1.0.0"
}

vaadin {
    version '12.0.0'
}

apply plugin: 'io.spring.dependency-management'

version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

springBoot {
    mainClassName = "com.cpsc471.TheatreManagmentApplicationKt"
}

repositories {
    mavenCentral()
    maven { url "https://maven.vaadin.com/vaadin-addons" }
    vaadin.repositories()
    // Add the pre-release repository
    vaadin.prereleases()
    // Add the snapshot repository
    vaadin.snapshots()
    // Add the addons repository
    vaadin.addons()
}

ext {
    set('vaadinVersion', '13.0.1')
}

noArg{
    annotation("MappedSuperclass")
}

dependencies { 
    implementation 'org.springframework.boot:spring-boot-starter-cache'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-tomcat'
    implementation "org.springframework.boot:spring-boot-starter-data-jpa"
    implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
    implementation 'com.vaadin:vaadin-spring-boot-starter:13.0.2'
    implementation 'org.jetbrains.kotlin:kotlin-reflect'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
    implementation 'org.springframework.retry:spring-retry' 

    implementation 'com.h2database:h2'

    implementation vaadin.bom()
    implementation vaadin.platform()
    implementation vaadin.lumoTheme()
    compile vaadin.springBoot()

    compileOnly 'org.projectlombok:lombok'

    runtimeOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'org.postgresql:postgresql'

    annotationProcessor 'org.projectlombok:lombok'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
}

dependencyManagement {
    imports {
        mavenBom "com.vaadin:vaadin-bom:${vaadinVersion}"
    }
}

compileKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}

compileTestKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}
主视图:

import com.cpsc471.model.types.User;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.value.ValueChangeMode;
import com.vaadin.flow.router.Route;

@Route(value = "test")
public class MainView extends VerticalLayout {

    private EmployeeEditor editor;
    private TextField filter;
    private Button addNewBtn;

    public MainView (EmployeeEditor editor) {
        setSizeFull();
        this.editor = editor;
        this.filter = new TextField();
        this.addNewBtn = new Button("New employee", VaadinIcon.PLUS.create());

        HorizontalLayout actions = new HorizontalLayout(filter, addNewBtn);
        add(actions, editor);

        filter.setPlaceholder("Filter by last name");
        filter.setValueChangeMode(ValueChangeMode.EAGER);
    }
}
自定义组件:

package com.cpsc471.model;

import com.cpsc471.model.types.User;
import com.vaadin.flow.component.KeyNotifier;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.annotation.UIScope;

import javax.swing.plaf.basic.BasicMenuUI;

@SpringComponent
@UIScope
public class EmployeeEditor extends VerticalLayout implements KeyNotifier {
    private User employee;

    private TextField firstName = new TextField("First name");
    private TextField lastName = new TextField("Last name");

    private Button save = new Button("Save", VaadinIcon.CHECK.create());
    private Button cancel = new Button("Cancel");
    private Button delete = new Button("Delete", VaadinIcon.TRASH.create());

    private HorizontalLayout actions = new HorizontalLayout(save, cancel, delete);
    private Binder<User> binder = new Binder<>(User.class);
    private BasicMenuUI.ChangeHandler changeHandler;
}
package com.cpsc471.model;
导入com.cpsc471.model.types.User;
导入com.vaadin.flow.component.KeyNotifier;
导入com.vaadin.flow.component.button.button;
导入com.vaadin.flow.component.icon.vaadicon;
导入com.vaadin.flow.component.orderedlayout.HorizontalLayout;
导入com.vaadin.flow.component.orderedlayout.VerticalLayout;
导入com.vaadin.flow.component.textfield.textfield;
导入com.vaadin.flow.data.binder.binder;
导入com.vaadin.flow.spring.annotation.SpringComponent;
导入com.vaadin.flow.spring.annotation.UIScope;
导入javax.swing.plaf.basic.BasicMenuUI;
@弹簧组件
@望远镜
公共类EmployeeEditor扩展VerticalLayout实现KeyNotifier{
私人用户雇员;
私有TextField firstName=新TextField(“firstName”);
私有TextField lastName=新TextField(“姓氏”);
私有按钮保存=新建按钮(“保存”,VaadinIcon.CHECK.create());
私人按钮取消=新按钮(“取消”);
private Button delete=新建按钮(“delete”,VaadinIcon.TRASH.create());
私有HorizontalLayout操作=新建HorizontalLayout(保存、取消、删除);
专用活页夹=新活页夹(User.class);
私有BasicMenui.ChangeHandler-ChangeHandler;
}
spring启动应用程序(kotlin):

import org.springframework.boot.autoconfigure.springboot应用程序
导入org.springframework.context.annotation.Bean
导入org.springframework.context.annotation.Configuration
导入org.springframework.security.config.annotation.web.builders.HttpSecurity
导入org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
导入org.springframework.security.config.annotation.web.configuration.websecurityConfigureAdapter
导入org.springframework.security.core.userdetails.User
导入org.springframework.security.core.userdetails.userdetails服务
导入org.springframework.security.provisioning.InMemoryUserDetailsManager
导入org.springframework.web.servlet.config.annotation.ViewControllerRegistry
导入org.springframework.web.servlet.config.annotation.WebMVCConfiguer
导入org.springframework.boot.SpringApplication
导入org.springframework.boot.web.servlet.support.SpringBootServletInitializer
@SpringBoot应用程序
类TheaterManAgmentApplication:SpringBootServletInitializer()
趣味主线(args:Array){
run(theatermagnementapplication::class.java,*args)
}
@配置
@启用Web安全性
类WebSecurityConfig:WebSecurityConfigureAdapter(){
@抛出(异常::类)
受保护的覆盖功能配置(http:HttpSecurity){
http
.授权请求()
.antMatchers(“/”、“/home”、“/h2/**”).permitAll()
.anyRequest().authenticated()
.及()
.formLogin()
.login页面(“/login”)
.permitAll()
.及()
.logout()
.permitAll()
http.csrf().disable()
http.headers().frameOptions().disable()
}
@豆子
覆盖有趣的userDetailsService():userDetailsService{
val user=user.withDefaultPasswordEncoder()
.用户名(“用户”)
.密码(“密码”)
.角色(“用户”)
.build()
返回InMemoryUserDetailsManager(用户)
}
}
@配置
类MvcConfig:WebMVCConfiguer{
覆盖视图控制器(注册表:ViewControllerRegistry){
registry.addViewController(“/home”).setViewName(“home”)
registry.addViewController(“/”).setViewName(“主页”)
registry.addViewController(“/hello”).setViewName(“hello”)
registry.addViewController(“/login”).setViewName(“login”)
}
}

您确定所有HTTP请求都没有错误吗?在浏览器开发工具中查看是否所有对资源(HTML、CSS、脚本)的请求都已成功响应。我想Spring安全配置是不够的,但我没有尝试过。检查。
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation .Bean
import org.springframework.context.annotation .Configuration
import org.springframework.security.config.annotation .web.builders.HttpSecurity
import org.springframework.security.config.annotation .web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation .web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.core.userdetails.User
import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.security.provisioning.InMemoryUserDetailsManager
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

import org.springframework.boot.SpringApplication
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer

@SpringBootApplication
class TheatreManagmentApplication : SpringBootServletInitializer()

fun main(args: Array<String>) {
    SpringApplication.run(TheatreManagmentApplication::class.java, *args)
}

@Configuration
@EnableWebSecurity
class WebSecurityConfig : WebSecurityConfigurerAdapter() {
    @Throws(Exception::class)
    protected override fun configure(http: HttpSecurity) {
        http
                .authorizeRequests()
                .antMatchers("/", "/home","/h2/**").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
                .logout()
                .permitAll()

        http.csrf().disable()
        http.headers().frameOptions().disable()
    }

    @Bean
    override fun userDetailsService(): UserDetailsService {
        val user = User.withDefaultPasswordEncoder()
                .username("user")
                .password("password")
                .roles("USER")
                .build()

        return InMemoryUserDetailsManager(user)
    }
}

@Configuration
class MvcConfig : WebMvcConfigurer {
    override fun addViewControllers(registry: ViewControllerRegistry) {
        registry.addViewController("/home").setViewName("home")
        registry.addViewController("/").setViewName("home")
        registry.addViewController("/hello").setViewName("hello")
        registry.addViewController("/login").setViewName("login")
    }
}