在第二周的数组运算符章节中,数组如下boxOffice
:
boxOffice: [{
"country": "USA",
"revenue": 41.3
}, {
"country": "Australia",
"revenue": 2.9
}, {
"country": "UK",
"revenue": 10.1
}, {
"country": "Germany",
"revenue": 4.3
}, {
"country": "France",
"revenue": 3.5
}]
Run Code Online (Sandbox Code Playgroud)
以下是获取英国收入大于 15的查询
db.movieDetails.find({
boxOffice: {
$elemMatch: {
country: "UK",
revenue: {
$gt: 15
}
}
}
})
Run Code Online (Sandbox Code Playgroud)
这里的困惑在于,查询过滤器默认在 MongoDB 的查找查询中进行AND编辑,这应该返回满足以下查询的country: "UK"
AND revenue: { $gt: 15 }
要求的文档:
db.movieDetails.find({
boxOffice: {
country: "UK",
revenue: {
$gt: 15 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建简单的REST请求处理程序,如下所示:
@RequestMapping(value = "test", method = RequestMethod.GET)
public String test(@RequestParam(name = "test", required = false) String test,
@RequestParam(name ="number", required = false) Long number) {
return new StringBuilder(test).append(" ").append(number).toString();
}
Run Code Online (Sandbox Code Playgroud)
但是当我通过CURL测试时:
curl http://localhost:8080/test?test=abc&number=2016
Run Code Online (Sandbox Code Playgroud)
输出结果如下:
abc null
Run Code Online (Sandbox Code Playgroud)
怎么了 这是我的错误还是Spring错误?我正在使用Spring Boot 1.4.0(可能是最新版本)。curl版本是7.43.0(64位)。
我正在使用Thymeleaf的Spring Boot,我正在尝试访问一个简单的网页.构建项目时我没有任何错误.访问时只有这一个localhost:8080/greeting
:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Dec 02 15:36:04 CET 2016
There was an unexpected error (type=Not Found, status=404).
No message available
Run Code Online (Sandbox Code Playgroud)
我有一个控制器:
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class UserController {
@RequestMapping("/greeting")
public String user(@RequestParam(value = "name", required = false, defaultValue = "World") String name, Model model){
model.addAttribute("name",name);
return "greeting";
}
}
Run Code Online (Sandbox Code Playgroud)
主要:
package boot; …
Run Code Online (Sandbox Code Playgroud) 有人可以提供一些想法来注入属性文件中的所有动态键和值,并将其传递Map
给DBConstants
使用Setter Injection with Collection的类。
密钥事先未知,可能会有所不同。
// Example Property File that stores all db related details
// db.properties
db.username.admin=root
db.password.admin=password12
db.username.user=admin
db.password.user=password13
Run Code Online (Sandbox Code Playgroud)
DBConstants
包含映射dbConstants,需要为其注入所有键和值。
请提供bean定义以将所有键和值注入Map dbConstants。
public class DBConstants {
private Map<String,String> dbConstants;
public Map<String, String> getDbConstants() {
return dbConstants;
}
public void setDbConstants(Map<String, String> dbConstants) {
this.dbConstants = dbConstants;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在保存Executive
与之关系的域对象UserAccount
,但在保存对象时会抛出一些错误:
WARN : org.hibernate.action.internal.UnresolvedEntityInsertActions - HHH000437: Attempting to save one or more entities that have a non-nullable association with an unsaved transient entity. The unsaved transient entity must be saved in an operation prior to saving these dependent entities.
Unsaved transient entity: ([com.sar.customerplus.entity.UserAccount#0])
Dependent entities: ([[com.sar.customerplus.entity.MarketingExecutive#300]])
Non-nullable association(s): ([com.sar.customerplus.entity.MarketingExecutive.userAccount])
org.springframework.dao.InvalidDataAccessApiUsageException: Not-null property references a transient value - transient instance must be saved before current operation : com.sar.customerplus.entity.MarketingExecutive.userAccount -> com.sar.customerplus.entity.UserAccount; nested exception is org.hibernate.TransientPropertyValueException: Not-null property references …
Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用$ location.path('/ enterprise/update /'+ enterprise.id)将我的应用程序重定向到以下链接;
当我点击按钮,当前URL是HTTP://本地主机:8080 /#/企业/视图
,我想它更改为HTTP://本地主机:8080 /#/企业/更新/ 0
(0在这里代表id)
编辑功能是我单击按钮重定向时调用的功能.
相关代码:EnterpriseCtrl.js
app.controller('EnterpriseCtrl', ['$scope', 'Enterprise', '$location','$http','$route','$routeParams','$resource', function($scope, Enterprise, $http, $route, $location, $rootScope) {
$scope.enterprises = Enterprise.list({}, function (response) {
return response;
});
$scope.add = function(){
Enterprise.save($scope.enterprise,function (){});
$scope.enterprise = null;
};
$scope.delete = function(enterprise, index){
alert("Do you really want to delete an Enterprise at index " + (index+1) + "?");
//book.$remove();
Enterprise.remove(enterprise);
$scope.enterprises.splice(index, 1);
};
$scope.edit = function(enterprise){
console.log(enterprise.id);
console.log(location);
console.log($location);
$location.path('/enterprise/update/' + enterprise.id);
};
// $scope.enterprise …
Run Code Online (Sandbox Code Playgroud) 是否有可能或解决方法告诉Spring Config Server从自身获取配置?我有一些针对所有Spring Boot应用程序的通用配置,具体取决于配置文件,并且我希望配置服务器能够不复制粘贴地访问它们。
我的Spring Boot应用程序中有一个类用于类型安全配置:
@Component
@ConfigurationProperties(prefix = "props")
@Getter
@Setter
public class Properties {
private String param1 = "val1";
private String param2 = "val2";
}
Run Code Online (Sandbox Code Playgroud)
后来我尝试在带有注释的bean中的字段上使用它: @Value("${props.param1}")
但是我在应用程序启动时遇到以下异常,直到我为我的自定义属性指定了一个值 application.properties
引起:java.lang.IllegalArgumentException:无法解析字符串值"$ {props.param1}"中的占位符'props.param1'
如何使Spring Boot应用程序使用默认值而不指定值application.properties
?
当我输入属性application.properties
并且存在defaultValue
生成spring-configuration-metadata.json
文件的内部时,我在IDE中看到默认值.我想这个默认值应该是spring,直到我在我的属性文件中进行操作,但由于未知原因,我从上面得到了例外.
我正在使用Spring Boot创建一个示例项目,并尝试/
使用简单的String消息进行映射.我@Controller
为此目的使用了注释.但由于某种原因,映射不起作用.我也包括@ComponentScan
和@EnableWebMvc
没有运气.
我已经使用了maven spring-boot:run
目标来运行.在https://github.com/tejact/SpringBasicsTreeHouse上传了该项目.
这是控制器:
package Controller;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Component
@Controller
public class GifController {
@RequestMapping("/")
@ResponseBody
public String listAllGifs() {
return "Listing all gifs : Madhu";
}
}
Run Code Online (Sandbox Code Playgroud)
主要应用条目:
package com.teja;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@EnableAutoConfiguration
@ComponentScan
@EnableWebMvc
public class AppConfig {
public static void main(String args[]) {
SpringApplication.run(AppConfig.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
和Spring Boot日志:
[INFO] Scanning for projects... …
Run Code Online (Sandbox Code Playgroud) using
以下代码段的含义是什么?
case Event(Task1('name', num, categ), _) => goto(RunAll) using ToAdd(num, categ)
Run Code Online (Sandbox Code Playgroud) java ×7
spring ×7
spring-boot ×4
spring-mvc ×2
angularjs ×1
curl ×1
hibernate ×1
javascript ×1
mongodb ×1
scala ×1
spring-cloud ×1
thymeleaf ×1