SpringBoot и AngularJs - обновить измененный файл stati c (js / html / css) в Intellij - PullRequest
1 голос
/ 22 марта 2020

Я использую Intellij для разработки приложений SpringBoot и AngularJs. Всякий раз, когда я изменяю файл stati c (html / js / css), я должен перезапускать приложение, чтобы изменения вступили в силу. Как я могу это сделать без перезапуска приложения. Это действительно пожирает мое время разработки.

Примечание: я пробовал Recompile <my-file> (Ctrl+Shift+F9) в Build меню, но оно не работает.

Вот пример приложения

СТРУКТУРА

enter image description here

ФАЙЛЫ

пом. xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.8.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>org.example</groupId>
<artifactId>SampleAngularJs</artifactId>
<version>1.0-SNAPSHOT</version>


<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>webjars-locator-core</artifactId>
    </dependency>

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>angularjs</artifactId>
        <version>1.7.9</version>
    </dependency>

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>angular-router</artifactId>
        <version>0.5.3</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Основной класс (Приложение. java)

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

   @Controller
   public static class Contr {
    @GetMapping("/welcome")
    public String welcome() {
        return "welcome";
    }

    @GetMapping("/templates/dashboard.html")
    public String dashboard() {
        return "dashboard";
    }
  }
}

индекс. html

<!DOCTYPE html >
<html lang="en">
  <head>
  <meta charset="UTF-8">
<title>Title</title>
 </head>
<body ng-app="my-app">
    <div ng-controller="LoginController">
        <label>Username</label>
        <input type="text" name="username"/>

        <label>Password</label>
        <input type="text" name="password"/>
        <button ng-click="login()">Login</button>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
    integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
    crossorigin="anonymous"></script>

<!--Angular Core-->
<script src="/webjars/angularjs/angular.min.js" type="text/javascript"></script>
<!--Angular router-->
<script src="/webjars/angularjs/angular-route.min.js" type="text/javascript"></script>

<script type="text/javascript">
angular.module('my-app', ['ngRoute'])
    .controller('LoginController', function ($scope, $window) {
        $scope.login = function () {
            $window.location.href = '/welcome';
        }
    });
</script>
</body>
</html>

Добро пожаловать. html

<!DOCTYPE html>
<html lang="en" ng-app="my-app">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

<div>
    <p>Main page with ng-view</p>
</div>

<div ng-view="" autoscroll="true"></div>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
    integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
    crossorigin="anonymous"></script>

<!--Angular Core-->
<script src="/webjars/angularjs/angular.min.js" type="text/javascript"></script>
<!--Angular router-->
<script src="/webjars/angularjs/angular-route.min.js" type="text/javascript"></script>

<script type="text/javascript">
var app = angular.module('my-app', ['ngRoute']);

app.config(function ($httpProvider, $routeProvider, $locationProvider) {
    $locationProvider.hashPrefix('');
    $routeProvider
        .when('/', {
            templateUrl: 'templates/dashboard.html',
            controller: ''
        })
        .otherwise(
            {redirectTo: '/'}
        );
    $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
});
</script>
</body>
</html>

панель приборов. html

<div>
    <h1>Dashboard View</h1>
</div>

Единственный обновляемый файл (Build > Recompile 'index.html') - index. html. Если я пытаюсь перекомпилировать (обновить) добро пожаловать. html или панель инструментов. html это не удастся.

1 Ответ

0 голосов
/ 27 марта 2020

Проблема не AngularJS с SpringBoot. Проблема в Thymeleaf и SpringBoot. В application.properties должна быть добавлена ​​конфигурация, которая отключает кэш SpringBoots Thymeleaf.

spring.thymeleaf.cache=false

Установите значение false.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...