您好,我正在尝试将 vavr 添加到我的项目中,现在我正在努力解决 Vavr.List 对象的正确序列化问题。下面是我的控制器:
import io.vavr.collection.List;
@GetMapping(value = "/xxx")
public List<EntityDeleted> getFile() {
return List.of(new EntityDeleted(true),new EntityDeleted(true),new EntityDeleted(true),new EntityDeleted(true));
}
Run Code Online (Sandbox Code Playgroud)
EntityDeleted 是我的自定义对象,List 是 Vavr 集合,如 import 语句所示。我在 Postman 中得到的回应是:
{
"empty": false,
"lazy": false,
"async": false,
"traversableAgain": true,
"sequential": true,
"singleValued": false,
"distinct": false,
"ordered": false,
"orNull": {
"deleted": true
},
"memoized": false
}
Run Code Online (Sandbox Code Playgroud)
我期望我的对象的 JSON 列表。下面是我的配置:
@SpringBootApplication
public class PlomberApplication {
public static void main(String[] args) {
SpringApplication.run(PlomberApplication.class, args);
}
@Bean
public ObjectMapper jacksonBuilder() {
ObjectMapper mapper = …Run Code Online (Sandbox Code Playgroud) 您好,我在 H2 控制台数据库中查看我的架构时遇到问题:
我使用弹簧靴:
spring.datasource.initialize=true
spring.datasource.url=jdbc:h2:~/test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MV_STORE=FALSE;MVCC=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true
Run Code Online (Sandbox Code Playgroud)
这是我的登录页面:
所以我在里面看到的是标准的控制台视图,没有我的表,但我的应用程序运行良好。
你好,我试图实现一个泛型方法作为控制器基方法,但我无法理解的问题发生在泛型方法签名上。
<T> ResponseEntity<T> makeApiCall(String path, HttpMethod httpMethod, T body, boolean isAdmin){
String sender = isAdmin ? adminHash : userHash;
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", sender);
headers.add("Content-Type", "application/json");
HttpEntity<T> entity = new HttpEntity<>(body,headers);
ResponseEntity<T> responseEntity = restTemplate.exchange(path, HttpMethod.POST, entity, body.getClass());
return responseEntity;
}
Run Code Online (Sandbox Code Playgroud)
我目前的编译错误如下:
Incompatible equality constraint: T and capture of ? extends Object
Run Code Online (Sandbox Code Playgroud) 我有以下架构:
项目 (ID, NAME) Projects_Users (PROJECT_ID, USERS_ID) 用户 (NAME, ID)
实体如下
public class Projects {
private String name;
private long id;
private List<User> users;
public Projects() {
}
}
public class User {
private String name;
private Long id;
}
Run Code Online (Sandbox Code Playgroud)
如此明显的一对多。项目可以有多个用户。
现在我的目标是编写 jooq 查询,我可以在其中获取已与相应用户一起使用的项目对象。
.select(PROJECT.NAME, PROJECT.ID, USERS)
.from(PROJECT)
.join(USERS_PROJECT).on(USERS_PROJECT.PROJECT_ID=PROJECT.ID)
.join(USERS).on(USERS.ID=USERS_PROJECT.USER_ID)
.fetchInto(Project.class);
Run Code Online (Sandbox Code Playgroud)
但是查询会在期望 ~15 时返回 thousends 结果
Im getting this error taht i dont really understand:
unbound pointcut parameter auditable
Run Code Online (Sandbox Code Playgroud)
following code:
@Aspect
public class TestAspect {
@Before(value = "@annotation(Action)")
public void audit(JoinPoint joinPoint, Action auditable) {
System.out.println(auditable);
}
}
@Action(ActionType.FAST)
public static void resolveFast(String name){
System.out.println(name);
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Action {
ActionType value();
boolean withArgs() default false;
}
public enum ActionType {
FAST, SLOW
}
Run Code Online (Sandbox Code Playgroud)
the problem occurs on @Before annotation, these are my first steps in aop...
我正在尝试使用ngrx store + ng效果为我的应用编写登录流程.我已经设法编写它并且它在快乐的场景中工作,但是当用户向表单输入错误的值,以便服务器响应401时,下一次登录尝试没有效果.我已经读过,在使用observable时必须捕获异常以便不"破坏"流,但据我所知,我已经捕获了异常并且它现在仍在工作.
代码下面;
export class LoginComponent {
logged = new Observable<any>();
constructor(private store: Store<AppStore>) {
this.logged = store.select('login');
}
login(username: string, password: string){
let body = JSON.stringify({username, password});
this.store.dispatch({type: LoginActions.ATTEMPT_LOGIN, payload: body});
}
}
@Injectable()
export class LoginEffects {
constructor(
private actions: Actions,
private loginService: LoginService
) { }
@Effect() login = this.actions
.ofType(LoginActions.ATTEMPT_LOGIN)
.map(toPayload)
.switchMap(payload => this.loginService.attemptLogin(payload))
.map(response => new LoginActions.LoginSuccess(response))
.catch(error => of(new LoginActions.LoginFailed(error)));
@Effect() success = this.actions
.ofType(LoginActions.LOGIN_SUCCESS)
.map(toPayload)
.map(payload => localStorage.setItem(Global.TOKEN, payload))
.map(() => …Run Code Online (Sandbox Code Playgroud) 大家好,我正在尝试掌握RxJS lib和反应式编程的整个思想。我正在尝试将两个可观察对象合并为一个。第一个可观察对象包含对象数组,DefectImages[]第二个可观察对象包含字符串数组,然后将其转换为 DefectImages[]。之后,我想将这两个可观察值合并为一个。
在我的代码下面:
const observable = CachedPhotosBuffer.getInstance().asObservable()
.pipe(
switchMap(data => {
return data.map((url) => DefectImage.createTempImage(url, 'you', Date.now()));
})
);
this.observable = Observable.create(observer => observer.next(this.defectImages));
this.observable.pipe(
merge(observable)
).subscribe(data => console.log('merge', data))
Run Code Online (Sandbox Code Playgroud)
这种类型的工作与我期望的一样,但此合并的Observables连接到html角度模板。
<ion-list>
**<ng-container *ngFor="let image of observable | async">**
<ion-item *ngIf="image.deletedAt === undefined">
<span class="item-container" (click)="showImage(image)">
<ion-thumbnail item-start>
<img id="{{image.url}}" src="{{getUrl(image) + image.url}}">
</ion-thumbnail>
<span>
<p>created at: {{image.createdAt | date: 'd/M/yy H:m'}}</p>
<p>created by: {{image.createdBy}}</p>
</span>
</span>
<button ion-button item-end (click)="removeImage(image)">
<ion-icon name="trash"></ion-icon>
</button>
</ion-item>
</ng-container> …Run Code Online (Sandbox Code Playgroud) 您好,我想通过查询排除一些字段。我正在使用 nodejs
public async getDoc() {
return new Promise((resolve, reject) => {
this.database.collection('users').find({email: "value3"}, {password: 0}).toArray((err, result) => {
if(err) {
reject(err)
}
resolve(result);
});
})
}
Run Code Online (Sandbox Code Playgroud)
但在结果集中我不断收到密码字段..
您好,我想知道在使用Spring Boot时如何将json消息映射到java中的对象。
假设我正在像
{
"customerId": 2,
"firstName": "Jan",
"lastName": "Nowak",
"town": "Katowice"
}
Run Code Online (Sandbox Code Playgroud)
并且我想在我的java程序中使其成为实体:出于任何原因,我都不 希望字段名匹配
public class Customer {
//Something like @Map("customerId")
private long OMG;
//Something like @Map("firstName")
private String WTF;
//Something like @Map("lastName")
private String LOL;
//Something like @Map("town")
private String YOLO;
Run Code Online (Sandbox Code Playgroud)
我找不到应该使用的注释,而不是仅使用spring boot转换器内置的jackson?
我在 url 上与邮递员进行 api 调用:
https://cex.io/api/order_book/BTC/USD
Run Code Online (Sandbox Code Playgroud)
简单的 GET 没有标题没有参数没有什么。但与 java 相同:
RestTemplate rt = new RestTemplate();
rt.getForObject("https://cex.io/api/order_book/BTC/USD", String.class);
Run Code Online (Sandbox Code Playgroud)
让我 403. 问题出在哪里?
所以我正在尝试测试我写的Spring启动MVC应用程序:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = PetClinicApplication.class)
@WebAppConfiguration
public class OwnerControllerTests {
@Mock
private OwnerService ownerService;
@InjectMocks
private OwnerController ownerController;
private MockMvc mockMvc;
public void setup(){
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.standaloneSetup(ownerController).build();
}
@Test
public void testOwnerList() throws Exception{
List<Owner> owners = new ArrayList<>();
owners.add(new Owner());
owners.add(new Owner());
when(ownerService.getAll()).thenReturn((List<Owner>) owners);
mockMvc.perform(get("/ownerList"))
.andExpect(status().isOk())
.andExpect(view().name("ownerList"))
.andExpect(model().attribute("ownerList", List.class));
}
}
Run Code Online (Sandbox Code Playgroud)
我快到了
when(ownerService.getAll()).thenReturn((List<Owner>) owners);
Run Code Online (Sandbox Code Playgroud)
在调试器模式ownerService = null这是OwnerService.class
@Transactional
public Collection<Owner> getAll() {
return ownerDao.getAll();
}
Run Code Online (Sandbox Code Playgroud)
此方法应返回Owner.class对象的列表
所有者控制器片段
@Controller
public class OwnerController {
@Autowired
private OwnerService ownerService;
@RequestMapping("/addOwner")
public …Run Code Online (Sandbox Code Playgroud) 我正在将对象导入到.ts文件中,但是undefined当我对关键字执行相同操作时require,它就可以工作。但我想了解发生了什么
const jwt = require('jsonwebtoken'); // working
import {jwt2} from 'jsonwebtoken'; // not working
Run Code Online (Sandbox Code Playgroud) java ×7
spring ×5
spring-boot ×4
angular ×2
jackson ×2
javascript ×2
node.js ×2
rxjs ×2
aop ×1
generics ×1
h2 ×1
jooq ×1
json ×1
junit ×1
mockito ×1
mongodb ×1
ngrx-effects ×1
ngrx-store ×1
sql ×1
typescript ×1
vavr ×1