我正在使用Jackson将我的JPA模型序列化为JSON.
我有以下课程:
import com.fasterxml.jackson.annotation.*;
import javax.persistence.*;
import java.util.Set;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class)
@Entity
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@JsonManagedReference
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<Child> children;
//Getters and setters
}
Run Code Online (Sandbox Code Playgroud)
和
import com.fasterxml.jackson.annotation.*;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
@Entity
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@JsonBackReference
@ManyToOne …Run Code Online (Sandbox Code Playgroud) 我有一个使用外部支付提供商购买积分的应用程序.成功购买后,付款服务提供商会重定向到http://any.url/?orderNr=xxxx&outcome=SUCCESS.这个url是一个使用UI路由器的AngularJS应用程序.路由器的配置如下:
$stateProvider
.state('dashboard', {
url: '/dashboard',
templateUrl: 'views/dashboard.html',
controller: 'DashboardCtrl',
isAuthenticated: true
})
.state('login', {
url: '/login',
templateUrl: 'views/login.html',
controller: 'LoginCtrl',
isAuthenticated: false
});
$urlRouterProvider.otherwise('/login');
Run Code Online (Sandbox Code Playgroud)
因此,当用户返回到root用户http://any.url并且已经登录时,它会重定向到仪表板.付款后就是这种情况,因为您无法在不登录的情况下进行付款.问题是hashbang位于查询字符串之后,因此仪表板的url变为http://any.url/?orderNr=xxxx&outcome=SUCCESS#/dashboard.在DashboardCtrl我无法获取查询字符串使用$location.search().有没有办法让查询字符串成为'角度方式',所以不能通过解析location.href?
我有一个集成测试课UserController.以下课程的内容如下:
// imports...
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
@Transactional
@Rollback
public class UserControllerTests {
private static final String ENDPOINT = "/v1/users";
@Autowired
private TestRestTemplate restTemplate;
@Autowired
private ApplicationProperties applicationProperties;
@Test
public void test_user_create() {
String token = login("test", "test");
HttpEntity<UserRequest> request = createRequest(token, "admin", "admin");
ResponseEntity<User> response = restTemplate.exchange(ENDPOINT, HttpMethod.POST, request, User.class);
assertEquals(HttpStatus.CREATED, response.getStatusCode());
}
private HttpEntity createRequest(String token) {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.set("Authorization", String.format("Bearer %s", token));
return new HttpEntity(headers);
}
private HttpEntity<UserRequest> createRequest(String token, String …Run Code Online (Sandbox Code Playgroud) 我在使用AngularJS的服务器上启用CORS时遇到问题.我正在使用Angular 1.2.16,这是我的服务器配置:
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Content-Type, X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Date, X-Api-Version, X-File-Name, Authorization"
Header set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
Header set Access-Control-Allow-Credentials "true"
Run Code Online (Sandbox Code Playgroud)
我可以使用以下请求:
$http.post(configuration.authUrl, {username: 'username', password: 'password'})
.success(function (data) {
$cookieStore.put(configuration.sessionName, {
token: data.authenticationToken,
user: data.user
});
})
.error(function () {}));
Run Code Online (Sandbox Code Playgroud)
因为此请求不使用自定义标头.
当我之后尝试请求以下内容时:
Balance.get()余额为:
angular.module('portalApp')
.factory('Balance', ['$resource', 'Auth', 'configuration', function ($resource, Auth, configuration) {
return $resource(configuration.balanceUrl, {}, {
get: {
method: 'GET',
isArray: false,
headers: {
Authorization: Auth.getAuthToken() …Run Code Online (Sandbox Code Playgroud) 我需要验证需要满足以下规则的密码:
我无法弄清楚如何使用正则表达式验证这一点.有谁能够帮我?
angularjs ×2
java ×2
javascript ×2
cors ×1
hibernate ×1
jackson ×1
jpa ×1
json ×1
junit ×1
postgresql ×1
regex ×1
spring ×1
spring-boot ×1
spring-jdbc ×1