我正在尝试运行此代码:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Exemple 06</title>
</head>
<body>
<!-- Diretiva ng-repeat -->
<div ng-controller="MyController">
<a ng-href="#/">Page 1</a> | <a ng-href="#/p2">Page 2</a>
<div ng-view="#/p2"></div>
</div>
<script src="js/angular.js"></script>
<script src="js/angular-route.js"></script>
<script type="text/javascript">
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function($routeProvider){
$routeProvider
.when('/' , {controller: 'MyController', templateUrl: 'p1.html'})
.when('/p2', {controller: 'MyController', templateUrl: 'p2.html'})
.otherwise({ redirectTo: '/'});
});
myApp.controller('MyController', function($scope){
$scope.nomes = [
{id: 1, nome: 'Arthur'},
{id: 2, nome: 'Portos'},
{id: 3, nome: 'Aramis'}
];
});
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
但是会出现以下错误:
XMLHttpRequest无法加载file:///home/93579551515/Desktop/Angular/p1.html.仅支持HTTP的跨源请求.
我不想在网络服务器上运行它.
我有一个实体需要有 UUID 类型的唯一键(非主键)。
@Entity
public class MyEntity {
@Id
@NotNull
@GeneratedValue(strategy = SEQUENCE, generator = "seq_entity")
@SequenceGenerator(name = "seq_entity", sequenceName = "seq_entity", allocationSize = 1)
private Long id;
@NotNull
@Type(type = "pg-uuid")
@Column(name = "uu_id", unique = true)
private UUID uuid;
@NotNull
@Size(max = 30)
private String name;
// gets and sets
}
Run Code Online (Sandbox Code Playgroud)
当我持久化这个实体时,可以在我的 DAO 类中看到下面的内容:
@Transactional
public class EntityDAO {
@Inject
private EntityManager em;
public void insert(MyEntity myEntity) { //myEntity comes only with name attribute
myEntity.setUUID(UUID.randomUUID()); //I'd like to …Run Code Online (Sandbox Code Playgroud) 当方法不获取记录时,如何配置 Spring Boot 以在 GET 方法(通常是 findAll 方法)中返回 204?我不想在每种方法中都做处理,键入下面的代码:
if(!result)
return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
return new ResponseEntity<Void>(HttpStatus.OK)
Run Code Online (Sandbox Code Playgroud)
我想改变这个方法:
@GetMapping
public ResponseEntity<?> findAll(){
List<User> result = service.findAll();
return !result.isEmpty() ?
new ResponseEntity<>(result, HttpStatus.OK) : new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
}
Run Code Online (Sandbox Code Playgroud)
在这个:
@GetMapping
public List<User> findAll(){
return service.findAll();
}
Run Code Online (Sandbox Code Playgroud)
如果findAll()的结果为空或 null,那么我的控制器应该返回204而不是200。