本文介绍了我想在java代码下面需要用jax-rs编写服务API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用jax-rs api编写代码请帮我任何人

感谢提前

sidda



i want to be written in jax-rs api below code please help me anybody
thanks for advance
sidda

package hellomongo;

import java.util.ArrayList;
import java.util.List;
 
import org.bson.Document;
import org.bson.types.ObjectId;

import com.mongodb.DB;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Updates;


public class Update {

public static void main(String args[]) {

	MongoClient client = new MongoClient("localhost", 27017);
	MongoDatabase database = client.getDatabase("admin");
	MongoCollection<Document> collection = database
			.getCollection("command");

Object id =  new ObjectId("5b16371c425750918ebf1454");
Document newCmd = new Document("d", 4);
collection.updateOne(Filters.eq("_id", id), Updates.addToSet("cmd", newCmd));

}

}





我的尝试:





What I have tried:

package com.api.restful;



 import java.util.ArrayList;
 import java.util.List;

 import javax.swing.text.Document;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;


 @Path("/command")


 public class InsertionAPi {

 @GET
 @Produces(MediaType.APPLICATION_JSON)
 public String sayHello(){
 MongoClient client = new MongoClient("localhost", 27017);
 MongoDatabase database = client.getDatabase("admin");
 MongoCollection<document> collection = database
 .getCollection("command");

 Object id = new ObjectId("5b16371c425750918ebf1454");
 Document newCmd = new Document("d", 4);
 collection.updateOne(Filters.eq("_id", id), Updates.addToSet("cmd", newCmd));

 return collection;


 }

 }

推荐答案


这篇关于我想在java代码下面需要用jax-rs编写服务API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 03:27