restTemplate用body删除

我正在尝试使用请求正文进行DELETE,但我一直收到400(错误的请求)错误。 当我在招摇/邮递员中这样做时,它成功删除了记录。 但是从Java代码我不能这样做 外部API的设计方式需要正文和URL。 它无法改变。 请告诉我如何删除请求正文的条目 public Person delete(Person person, String url, Map uriVariables) throws JsonProcessingException { RestTemplate restTemplate = new RestTemplate(); CustomObjectMapper mapper = new CustomObjectMapper(); HttpEntity requestEntity = new HttpEntity(person); try { ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, Person.class, uriVariables); return responseEntity.getBody(); } catch (RestClientException e) { System.out.println(mapper.writeValueAsString(person)); throw e; } } 当它转到exception时,我将以JSON格式获得JSON请求,并且在Swagger […]

如何阅读Android中的Chrome历史记录

是否可以只阅读历史记录? 通过使用以下代码,我可以同时获取历史记录和书签,但我只想阅读历史记录。 String[] proj = new String[] { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL }; String chnHistory = Browser.BookmarkColumns.BOOKMARK + ” = 0″+” OR visits > 0″; // 0 = history, 1 = bookmark mycur = getContentResolver().query(Browser.BOOKMARKS_URI, proj, chnHistory, null, null); int count = mycur.getCount(); mycur.moveToFirst(); array = new ArrayList(); if (mycur.moveToFirst() && count > 0) { while (count […]

如何为java中的ValueRange变量赋值?

我正在尝试使用此网页中的以下代码将Google工作表API编写function实施到我的应用中,但无法弄清楚如何为ValueRange变量赋值。 public class SheetsExample { public static void main(String args[]) throws IOException, GeneralSecurityException { // The ID of the spreadsheet to update. String spreadsheetId = “my-spreadsheet-id”; // TODO: Update placeholder value. //The A1 notation of the values to update. String range = “my-range”; // TODO: Update placeholder value. // TODO: Assign values to desired fields […]

包装线,右对齐,自动调整JTable中的行高

我编写了一个Java应用程序,我需要一个JTable类的对象,它具有一些特性: 自动包装线 正确对齐 自动调整行高(这意味着例如行的大小为25,但表中另一行的大小为50,内容大小为行) 渲染速度必须很高 但是我的代码不能快速完成并且没有完全的顶级function,我在最后一个问题中编写了我的应用程序的最小版本: 这是我的gui课程: import javax.swing.*; import java.awt.*; public class GUI extends JFrame { private BankTable table; private JScrollPane scrollPane; public GUI(){ super(“Bank Table”); JPanel contentPanel = new JPanel(); setContentPane(contentPanel); contentPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); setLayout(new BorderLayout()); setMinimumSize(new Dimension(1000,700)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); makeTable(); scrollPane = new JScrollPane(table); scrollPane.getVerticalScrollBar().setUnitIncrement(50); add(scrollPane,BorderLayout.CENTER); setVisible(true); } public void makeTable(){ String[][]data= new String[][]{{“0212670003009”, “ص […]

在ZeroMQ中使用Java中的SUB没有消息匹配

我正在尝试使用ZeroMQ的Java客户端。 订阅任何前缀时,Java客户端不匹配任何消息,尽管类似的Python客户端按预期匹配消息。 Python服务器 context = zmq.Context() socket = context.socket(zmq.PUB) socket.bind(“tcp://*:5556”) for i in range(100): r = “XXX ” + i socket.send_string(r) time.sleep(random.randint(0,10)) Python客户端正常工作 context = zmq.Context() socket = context.socket(zmq.SUB) socket.connect(“tcp://localhost:5556”) zip_filter = “XXX” socket.setsockopt_string(zmq.SUBSCRIBE, zip_filter) for update_nbr in range(5): s = socket.recv_string() print(s) Java客户端不匹配任何消息 context = ZMQ.context(1); subscriber = context.socket(ZMQ.SUB); subscriber.connect(“tcp://localhost:5556”); String filter = “XXX”; […]

处理Tomcat servlet中的重复GET请求(由Trendmicro引起)

在Apache Tomcat servlet中处理来自同一客户端的重复GET请求的最佳策略是什么? 基本上,我得到的是2个请求相隔几秒钟,第一个来自客户端的真实IP,第二个来自TrendMicro服务器(这看起来与此处描述的效果相同)。 现在我的servlet忠实地为这两个请求提供服务但稍后会产生问题(因为它调用了另一个很可能无法处理这种情况的远程服务)。 所以问题是,如何阻止第二个请求? 或者还有其他策略可以解决这个问题吗? 谢谢!

从内部类中获取事件,扩展SwingWorker

我试图从内部类中触发事件,但它不起作用。 这是我的代码: 摘要型号: public abstract class AbstractModel { public PropertyChangeSupport propertyChangeSupport; public AbstractModel() { propertyChangeSupport = new PropertyChangeSupport(this); } public void addPropertyChangeListener(PropertyChangeListener listener) { propertyChangeSupport.addPropertyChangeListener(listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { propertyChangeSupport.removePropertyChangeListener(listener); } protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); } } 模型: public class GUImodel extends AbstractModel { // […]

如何从按距离排序的JPA实体获得结果?

我目前正在编写一个移动应用程序,用户必须从列表中选择一个位置。 使用来自Play应用程序的JPA将所有位置存储在Postgres数据库中。 我想要做的是在应用程序中获取用户位置,然后请求获取离该用户最近的前20或50个位置。 如果我使用自己的数据结构,我会使用KD-Tree。 但是,我对JPA / Play / PostgreSQL很新,所以我不确定如何手动处理数据持久性。 我能用现有的知识来思考的唯一事情就是查看每个位置并确定它的距离,但是在如此庞大的数据库中,这个速度会非常慢。 有没有一个查询我可以说“给我X的第一个结果按照这个纬度和经度的距离排序? 编辑:我正在使用Heroku,因为应用程序处于开发的早期阶段,如果你想在你的应用程序中使用PostGIS,我宁愿不必支付每天200美元的Heroku费用。

ImageView getLocationtOnScreen android

我想在屏幕上获取图像的坐标。 我目前在活动中有一个ImageView。 我知道只有在创建布局后才能调用getLocationOnScreen()方法,因此在oncreate函数中调用此方法将返回[0,0]。 但我不知道如何让这个方法返回正确的值。 我试过覆盖各种超类方法,比如onstart方法或onTouchEvent方法,它仍然向我返回[0,0]。 我目前的代码如下: @Override public void onCreate(Bundle savedInstanceState) { // Some code here after which .. image = (ImageView) findViewById(R.id.imageVfi); image.setImageBitmap(imageData.entrySet().iterator().next().getValue()); } 然后我有onStart方法,我已经覆盖 @Override public void onStart() { super.onStart(); image.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int[] dim = new int[2]; image.getLocationOnScreen(dim); new AlertDialog.Builder(DisplayPicture.this) .setIcon(R.drawable.icon) .setTitle(“Touch coordinates : ” […]

java.util.regex.Matcher困惑组

我无法获得正确的正则表达式匹配组。 我的代码归结为以下内容: Pattern fileNamePattern = Pattern.compile(“\\w+_\\w+_\\w+_(\\w+)_(\\d*_\\d*)\\.xml”); Matcher fileNameMatcher = fileNamePattern.matcher(“test_test_test_test_20110101_0000.xml”); System.out.println(fileNameMatcher.groupCount()); if (fileNameMatcher.matches()) { for (int i = 0; i < fileNameMatcher.groupCount(); ++i) { System.out.println(fileNameMatcher.group(i)); } } 我希望输出为: 2 test 20110101_0000 它然而: 2 test_test_test_test_20110101_0000.xml test 有没有人有解释?