我正在尝试将以下对象转换为查询字符串,以便可以与 GET 请求一起使用。
Class A {
String prop1;
String prop2;
Date date1;
Date date2;
ClassB objB;
}
Class B {
String prop3;
String prop4;
}
Run Code Online (Sandbox Code Playgroud)
我们可以将第一个对象转换为 Map 然后将 map 转换为 MultiValueMap 并使用 URIComponentsBuilder.fromHttpUrl("httpL//example.com").queryParams(multiValueMap).build();
是否有更短更好的方法将对象转换为查询字符串,以便在 Spring 项目中用于 Junit 测试的 GET 请求?
如果我的做法有误,请指正。
在我的 Web 应用程序中,我没有使用 jsp 页面来开发用户界面。相反,我使用 html、css 和 Angular 2,并且前端项目结构与后端分离。
尽管我能够使用由 SpringMVC 后端提供服务的 Angular CLI 开发一个简单的项目。前端正在使用端口 4200,后端在端口 8080 上运行。我设法将请求从 Angular 2 获取并提供给 SpringMVC。在本地模式下,这些工作完美,现在我想让它们托管在实时服务器上。
如何分别发布 SpringMVC 后端和 Angular 2 前端但运行在同一个域上?我没有使用 SpringBoot,前端和后端也在不同的文件夹中。我不想将两者结合在同一个项目结构中并生成一个战争文件并进行部署。
开发 SpringMVC 后端和 Angular-2 后端并将它们部署在在线服务器中的最佳实践是什么?
我想在mockito单元测试中获得异常的json响应。这是我的应用程序配置文件。
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.spring")
public class AppConfig extends WebMvcConfigurerAdapter{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我现有用户的异常类:
public class ConflictException extends RuntimeException{
public ConflictException() {
}
public ConflictException(String message) {
super(message);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的全局异常控制器类,用 @ControllerAdvice 注释。
@EnableWebMvc
@ControllerAdvice
public class GlobalExceptionHandlerController extends ResponseEntityExceptionHandler{
public GlobalExceptionHandlerController() {
super();
}
@ExceptionHandler(ConflictException.class)
public ResponseEntity<Map<String, Object>> handleException(
Exception exception, HttpServletRequest request) {
ExceptionAttributes exceptionAttributes = new DefaultExceptionAttributes();
Map<String, Object> responseBody = exceptionAttributes.getExceptionAttributes(exception, request, HttpStatus.CONFLICT);
return new ResponseEntity<Map<String,Object>>(responseBody, HttpStatus.CONFLICT);
}
} …Run Code Online (Sandbox Code Playgroud) 我正在学习 ag-grid 并尝试使用以下代码在我的应用程序中显示复选框。
在 app.component.html 中:
<ag-grid-angular
style:"width: 500px; height: 500px;"
class: "ag-theme-balham"
[rowData]="rowData"
[columnDefs]="columnDefs"
rowSelection="multiple"
[gridOptions]="gridOptions"
[gridReady]="onGridReady($event)">
</ag-grid-angular>
Run Code Online (Sandbox Code Playgroud)
在 AppComponent.ts 中:
export class AppComponent implements OnInit {
@ViewChild('agGrid')
agGrid: AgGridNg2;
private gridApi;
private gridColumnApi;
gridOptions: GridOptions;
columnDefs = [
{headerName: 'Make', field: 'make', checkboxSelection: true},
{headerName: 'Model', field: 'model'}
{headerName: 'Price', field: 'price'},
];
rowData: [
{make: 'Toyota', model: 'Celica', price: 35000},
{make: 'Ford', model: 'Mondeo', price: 32000},
{make: 'Porsche', model: 'Boxter', price: 72000}
];
onGridReady() {
this.gridApi = …Run Code Online (Sandbox Code Playgroud) 我需要以下输出。
NE 50
SE 80
Run Code Online (Sandbox Code Playgroud)
我正在使用猪查询来计算基于区域的国家/地区。
c1 = group country by zone;
c2 = foreach c1 generate COUNT(country.zone), (
case country.zone
when 1 then 'NE'
else 'SE'
);
Run Code Online (Sandbox Code Playgroud)
但我无法实现我的输出。我收到如下错误:
2016-03-30 13:57:16,569 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1039: (Name: Equal Type: null Uid: null)incompatible types in Equal Operator left hand side:bag :tuple(zone:int) right hand side:int
Details at logfile: /home/cloudera/pig_1459370643493.log
Run Code Online (Sandbox Code Playgroud)
但我能够使用以下查询。
c2 = foreach c1 generate group, COUNT(country.zone);
Run Code Online (Sandbox Code Playgroud)
这将提供以下输出:
(1,50)
(2,80)
Run Code Online (Sandbox Code Playgroud)
如何添加 NE 而不是 1 和 SE 而不是 2?我认为使用 CASE 会有所帮助,但出现错误。任何人都可以帮忙吗?
java ×3
angular ×2
spring ×2
ag-grid ×1
apache-pig ×1
exception ×1
hadoop ×1
junit ×1
mockito ×1
radio-button ×1
spring-mvc ×1
unit-testing ×1