小编bur*_*ete的帖子

百里香叶;“模板解析期间发生错误”

I\xc2\xb4m 当前在使用 springboot 时遇到问题,并且出现错误“模板解析期间发生错误(模板:“类路径资源 [templates/mainpage.html])”。

\n\n

我\xc2\xb4ve尝试重新安装不同版本的lombok,因为我认为这可能是问题所在,但到目前为止似乎没有任何效果。我\xc2\xb4m 使用 gradle 和 Eclipse 作为 IDE。\n感谢任何帮助,由于不同的 springBootVersions,发现了一些具有相同问题的线程,但尝试了旧的和新的,它也没有\xc2\xb4t 为我修复它。

\n\n

我的build.gradle看起来像这样:

\n\n
buildscript {\next {\n    springBootVersion = \'2.0.3.RELEASE\'\n}\nrepositories {\n    mavenCentral()\n}\ndependencies {\n    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")\n}\n}\n\napply plugin: \'java\'\napply plugin: \'eclipse\'\napply plugin: \'org.springframework.boot\'\napply plugin: \'io.spring.dependency-management\'\n\ngroup = \'test\'\nversion = \'0.0.1-SNAPSHOT\'\nsourceCompatibility = 1.8\n\nrepositories {\n mavenCentral()\n}\n\ndependencies {\n  compile(\'org.springframework.boot:spring-boot-starter-thymeleaf\')\n  compile(\'org.springframework.boot:spring-boot-starter-web\')\n  runtime(\'org.springframework.boot:spring-boot-devtools\')\n  testCompile(\'org.springframework.boot:spring-boot-starter-test\')\n  compileOnly \'org.projectlombok:lombok:1.18.2\'\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的控制器

\n\n
package test;\n\nimport org.springframework.stereotype.Controller;\nimport org.springframework.ui.Model;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.PostMapping;\n\n@Controller\npublic class ExampleController {\n\n    @GetMapping(path = "/")\n    public String mainpage(Model model) {\n        return "mainpage";\n    }\n\n    @PostMapping(path = …
Run Code Online (Sandbox Code Playgroud)

thymeleaf spring-boot

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

Spring Boot 2 - 禁用 Envers

如何Hibernate Envers在 Spring Boot 2 中禁用?我不想删除依赖项,因为代码依赖于它取决于环境。

我在我的中尝试了以下属性,application.properties但没有奏效。启动时总是打印envers enabled = true

spring.hibernate.integration.envers.enabled=false
hibernate.integration.envers.enabled=false
spring.jpa.hibernate.integration.envers.enabled=false
Run Code Online (Sandbox Code Playgroud)

hibernate-envers spring-boot

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

无法自动接线。找不到“存储库”类型的bean

我正在使用Spring Data Jpa,这是我的项目结构:

App
  ConfigPackage
    MyConfig
  ServicePackage
    MyService
  RepositoryPackage
    MyRepository
Run Code Online (Sandbox Code Playgroud)

这是MyRepository

public interface MyRepository extends JpaRepository<MyEntity, Long> {
}
Run Code Online (Sandbox Code Playgroud)

这是MyService

@Service
public class MyService {

    @Autowired
    private MyRepository myRepository; <---here

    ...
}
Run Code Online (Sandbox Code Playgroud)

这是MyConfig

@Configuration
@EnableJpaRepositories(
        basePackages = "RepositoryPackage",
        entityManagerFactoryRef = "xxx",
        transactionManagerRef = "xxx"
)
public class MyConfig {
}
Run Code Online (Sandbox Code Playgroud)

我用@Autowired注入MyRepositoryMyService,但的IntelliJ总是抱怨

无法自动接线。找不到“ MyRepository”类型的bean

即使代码可以编译并成功运行。

为什么IntelliJ无法识别这不是错误?如何清除IntelliJ的警告?

IntelliJ版本:2018.2.6

java spring intellij-idea spring-data-jpa spring-boot

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

在Spring Boot执行器运行状况检查API中启用日志记录

我正在使用Spring boot Actuator API进行运行状况检查端点,并通过以下方式启用了它:

management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=healthcheck
Run Code Online (Sandbox Code Playgroud)

这里提到

现在,当上述状态/healthcheck失败时,我想在我的应用程序日志文件中启用日志,并从此端点打印整个响应。

实现此目的的正确方法是什么?

java logging spring-boot spring-boot-actuator

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

java HashMap如何链接?如何访问所有碰撞值?

我在某处读过HashMap使用链接来解决冲突.但如果是这样的话.如何访问具有相同键值的所有元素.

例如 :

HashMap<Integer, String> hmap = new HashMap<Integer, String>();
hmap.put(1, "1st value");
hmap.put(1, "2nd value");
hmap.put(1, "3rd value");
hmap.put(1, "4th value");
Run Code Online (Sandbox Code Playgroud)

现在,如果我做hmap.get(1)它返回"第四个值"

如果确实它确实像链接一样

键值1"第四值"--->"第三值"--->"第二值"---->"第一值"

我怎样才能获得其他值?

hmap.get(1) 只返回第一个值.

我的第二个问题是,

如果它做线性链接.如何删除键的任何一个值.假设我想从我的hashmap中删除"4th value"并希望保留相同键的所有其他值,我该怎么办?

如果我做

hmap.remove(1);

,它删除了完整的链.

java collections data-structures

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

使用Spring Data Rest发布到集合关联

我很难创建一个可以POST的集合关联.我有两个实体,设备和组,具有多对多关系.这样设备可以是零个或多个组,组可以包含零个或多个设备.

我可以通过POST到/ api/devices和/ api/groups /创建新的设备和组实体.从我对文档的阅读中,设备集合中的设备应该有一个RestResource,它表示设备所属的组的集合(即/ api/devices/{deviceId}/groups.这是一个"关联资源",因为它是Set<Group>我的一个实例,我会认为它被认为是一个收集协会.我可以得到和PUT uri-lists到这个协会,但当我发布它,我得到一个404.

列表可能会变得非常大,我希望能够发布一个新的链接到集合关联,而不必下载整个东西修改它和PUT它回来.

documenation说,这应该是支持的,但我有没有运气.

任何建议都将非常感激.

这些域类定义为:

@Entity
public class Device {
    @Id
    @GeneratedValue
    private Long id;

    private String name;

    @ManyToMany(targetEntity = Group.class, cascade = CascadeType.ALL)
    private Set<Group> groups;

    // getters, setters
}
Run Code Online (Sandbox Code Playgroud)

和,

@Entity(name="device_groups")
public class Group {
    @Id @GeneratedValue
    private Long id;

    private String name;

    @ManyToMany(mappedBy = "groups")
    private Set<Device> devices;

    // getters, setters
}
Run Code Online (Sandbox Code Playgroud)

每个人都有一个声明的存储库:

public interface DeviceRepository extends PagingAndSortingRepository<Device, Long> {
}

public interface GroupRepository …
Run Code Online (Sandbox Code Playgroud)

rest spring jpa spring-data-rest

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

有没有办法获取mongodb中对象字段的长度?

我有以下对象MongoDB

[
    {
        "name": "pencil",
        "purchase_record": {
            "1":"$900",
            "2":"$1000",
            "3":"$1100",
            "4":"$1200"
        }
    },
    {
        "name": "pen",
        "purchase_record": {
            "1":"$1000",
            "2":"$1200",
            "3":"$900",
            "4":"$1100",
            "5":"$1100"
        }
    }
]
Run Code Online (Sandbox Code Playgroud)

purchase_record有没有办法获得每条记录的长度?

mapreduce mongodb mongodb-query aggregation-framework

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

网络工作者在执行时抛出 404

我的项目结构看起来像

js
  /client.js
  /script1.js
  /webWoker.js
node_modules
.gitignore
index.html
Run Code Online (Sandbox Code Playgroud)

main.html有它作为以及包括

<script type="text/javascript" src="js/script1.js"></script>
<script type="text/javascript" src="js/client.js"></script>
<script type="text/javascript" src="js/webWoker.js"></script>
Run Code Online (Sandbox Code Playgroud)

我的script1.js样子

if (window.Worker) {
    console.log("uri: " + document.documentURI);
    var myWorker = new Worker("myworker.js");
    myWorker.postMessage("hello");
    console.log(myWorker);

    myWorker.onmessage = function (e) {
        result.textContent = e.data;
        console.log('Message received from worker: ' + result.textContent);
    };
}
Run Code Online (Sandbox Code Playgroud)

我的webWorker.js样子

onmessage = function (e) {
    console.log('Message received from main script');
    var result = "#27ae60";
    console.log('Posting message back to main script');
    postMessage(result);
};
Run Code Online (Sandbox Code Playgroud)

我 …

javascript web-worker node.js

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

Springboot 如何在 POST 后返回响应

我想创建一个新客户并在创建客户后返回一个客户编号。客户编号必须是从 50000 开始自动递增的唯一编号。

到目前为止,我已经成功创建了一个客户,但我不确定我应该如何生成客户编号,将其保存到数据库中,并在触发 POST 时将其作为成功消息显示给用户。

json 下面是所需的响应;

{
    "customerNumber": "50002",
    "statusMessage": "Customer Created Successfully",
} 
Run Code Online (Sandbox Code Playgroud)

以及来自控制器和服务的以下片段;

用户服务.java

public void createUser(User user) {
    if (user == null || user.getId() == null) {
        throw new ResourceNotFoundException("Empty", "Missing Data Exception");
    } else {
        userRepository.save(user);
    }
}
Run Code Online (Sandbox Code Playgroud)

注册控制器.java

@RequestMapping(method = RequestMethod.POST, value = "/users")
public void createUser(@RequestBody User user) {
    userService.createUser(user);
}
Run Code Online (Sandbox Code Playgroud)

java rest response spring-boot

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

if - else在laravel框架刀片模板中不起作用

我的问题是,我有Laravel刀片模板的页面.如果用户已登录,则应从主布局扩展我的页面.如果用户没有登录,我的页面应该从另一个主布局扩展.

但我的if-else声明不起作用

 <?php 
 if (Auth::check()){?>
 @extends('layouts.outside');
 <?php } else{ ?>
     @extends('layouts.admin');
 <?php }?>
Run Code Online (Sandbox Code Playgroud)

我也试过刀片if-else版本如下:

@if (Auth::check())
 @extends('layouts.outside')
@else
 @extends('layouts.admin')
@endif
Run Code Online (Sandbox Code Playgroud)

它也不起作用.每次在语句中为true或false时,if和else语句中的块都会运行一次.因为没有别的.我的意思是每次它调用layouts.outside一次并且只是底部,同样的页面再次加载layouts.outside,无论用户是否登录都无关紧要.

谢谢

php if-statement laravel blade

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