diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b55194 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# ---> Java +# Compiled class file +*.class +.idea +.idea/* +.gradle +out +build + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..b081818 --- /dev/null +++ b/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'java' + id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'org.springframework.boot' version '2.6.4' +} + +jar { + archivesBaseName = 'example-web' +} + +group 'ru.ulstu' +version '1.0-SNAPSHOT' + +repositories { + maven { + url "http://repo.athene.tech/repository/maven-central/" + allowInsecureProtocol(true) + } +} + +dependencies { + ext { + versionSLF4J = '1.7.24' + versionJetty = '9.3.16.v20170120' + versionJackson = '2.9.4' + versionSwagger = '2.5.0' + } + + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jetty' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation' + implementation group: 'org.slf4j', name: 'slf4j-api', version: versionSLF4J + implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '3.1.0' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' + testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..d66f36f --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Dec 28 10:00:20 PST 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip diff --git a/src/main/java/ru/ulstu/ExampleWebApplication.java b/src/main/java/ru/ulstu/ExampleWebApplication.java new file mode 100644 index 0000000..5c56791 --- /dev/null +++ b/src/main/java/ru/ulstu/ExampleWebApplication.java @@ -0,0 +1,13 @@ +package ru.ulstu; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; + +@SpringBootApplication +@EnableConfigurationProperties +public class ExampleWebApplication { + public static void main(String[] args) { + SpringApplication.run(ExampleWebApplication.class, args); + } +} diff --git a/src/main/java/ru/ulstu/configuration/MvcConfiguration.java b/src/main/java/ru/ulstu/configuration/MvcConfiguration.java new file mode 100644 index 0000000..380f152 --- /dev/null +++ b/src/main/java/ru/ulstu/configuration/MvcConfiguration.java @@ -0,0 +1,49 @@ +package ru.ulstu.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.LocaleResolver; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.i18n.CookieLocaleResolver; +import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; + +@Configuration +public class MvcConfiguration implements WebMvcConfigurer { + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/login"); + registry.addViewController("/loginError"); + registry.addViewController("/index"); + registry.addViewController("/admin"); + registry.addViewController("/organizers"); + registry.addViewController("/docs"); + registry.addViewController("/editNews"); + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry + .addResourceHandler("/webjars/**") + .addResourceLocations("/webjars/"); + } + + @Bean + public LocaleResolver localeResolver() { + return new CookieLocaleResolver(); + } + + @Bean + public LocaleChangeInterceptor localeInterceptor() { + LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor(); + localeInterceptor.setParamName("lang"); + return localeInterceptor; + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(localeInterceptor()); + } +} diff --git a/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java b/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java new file mode 100644 index 0000000..d3d9627 --- /dev/null +++ b/src/main/java/ru/ulstu/configuration/TemplateConfiguration.java @@ -0,0 +1,19 @@ +package ru.ulstu.configuration; + +import nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.thymeleaf.spring5.SpringTemplateEngine; +import org.thymeleaf.templateresolver.ITemplateResolver; + +@Configuration +public class TemplateConfiguration { + + @Bean + public SpringTemplateEngine templateEngine(ITemplateResolver templateResolver) { + final SpringTemplateEngine templateEngine = new SpringTemplateEngine(); + templateEngine.addTemplateResolver(templateResolver); + templateEngine.addDialect(new LayoutDialect()); + return templateEngine; + } +} diff --git a/src/main/java/ru/ulstu/controller/IndexController.java b/src/main/java/ru/ulstu/controller/IndexController.java new file mode 100644 index 0000000..358f6ee --- /dev/null +++ b/src/main/java/ru/ulstu/controller/IndexController.java @@ -0,0 +1,14 @@ +package ru.ulstu.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class IndexController { + + @GetMapping("/") + public String index(Model model) { + return "index"; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..b251eab --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.main.banner-mode=off +server.port=8080 diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html new file mode 100644 index 0000000..0ffd70f --- /dev/null +++ b/src/main/resources/templates/default.html @@ -0,0 +1,17 @@ + + + + + app-name + + + +
+ Стартовая страница +
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/error/403.html b/src/main/resources/templates/error/403.html new file mode 100644 index 0000000..9eb069c --- /dev/null +++ b/src/main/resources/templates/error/403.html @@ -0,0 +1,13 @@ + + + + + +
+
Доступ запрещён
+
Вернуться на главную
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/error/404.html b/src/main/resources/templates/error/404.html new file mode 100644 index 0000000..d599650 --- /dev/null +++ b/src/main/resources/templates/error/404.html @@ -0,0 +1,13 @@ + + + + + +
+
Страница не найдена
+
Вернуться на главную
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/error/500.html b/src/main/resources/templates/error/500.html new file mode 100644 index 0000000..b77a6cf --- /dev/null +++ b/src/main/resources/templates/error/500.html @@ -0,0 +1,13 @@ + + + + + +
+
Ошибка сервера
+
Вернуться на главную
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..6d60c0b --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,7 @@ + + +
+ +
+