如何配置Square的Retrofit Client来处理具有可变数量参数的请求

我正在构建一个Android应用程序,并使用Square的Retrofit库进行短期网络调用。 我对Java和Android比较陌生。 到目前为止,我已经构建了这样的请求: @GET(“/library.php”) void library( @Query(“one_thing”) String oneThing, @Query(“another_thing”) String anotherThing, Callback<Map> callback ); 并称它们为: service.library(oneThing, anotherThing, callback); 我需要实现一个接受可变数量参数的请求,不超过10个左右。 必须单独定义它们并为给定请求不存在的那些传递null或其他东西是很麻烦的。 有没有办法为请求定义一个接口,以便它接受一个或多个变量参数,并为参数字典/映射中的每个元素自动构造@Query ? 像这样的东西: @GET(“/library.php”) void library( Map parameters, Callback<Map> callback ); service.library(parameters, callback); 提前感谢任何提示。 编辑:为与请求无关的参数传递null在这种情况下不起作用。 理想情况下,我可以根据参数字典设置/创建@Query ,这样如果键值为null,键就不会成为@Query 。 编辑:我特意寻找适用于GET请求的解决方案。

是否可以在忽略每个字符串中的前3个字符的同时对数组列表进行排序?

我试图弄清楚如何按字母顺序对列表进行排序,通常这很容易,但我需要忽略列表中每个字符串的前5个字符。 (它们是数字IDS) ArrayList tempList = new ArrayList(); for(String s : AddressBook){ tempList.add(s); Collections.sort(tempList ); } System.out.println(tempList);

JAXB是否始终需要XSD

http://www.oracle.com/technetwork/articles/javase/index-140168.html#binsch – 本文说“ JAXB要求您要访问的XML文档具有架构 ” 这是一个Hello World示例,使用hello.xsd http://jaxb.java.net/tutorial/section_1_3-Hello-World.html#Hello%20World- 这是一个不使用任何xsd的Hello World示例。 http://www.mkyong.com/java/jaxb-hello-world-example/ 规范是否说JAXB在没有 xsd的情况下也可以工作,如果这是真的那么术语“绑定”的合理程度。 我相信通过绑定模式发生绑定。 Carification将会很有帮助。 谢谢

配置为目标的PN532已由其启动器释放

我试图将我的PN532置于卡仿真模式。 当我发送TgGetData命令时,错误我从阅读器返回错误。 1。 读取寄存器 {(byte)0xFF,0x00,0x00,0x00,0x08, (byte)0xD4, 0x06, 0x63, 0x05, 0x63, 0x0D, 0x63, 0x38 } RESPONSE :: D507 07 07 15 9000 2。 更新寄存器 byte xx = (byte) 07; byte yy = (byte) 07; byte zz = (byte) 15; xx = (byte) (xx | 0x004); yy = (byte) (yy & 0x0EF); zz = (byte) (zz & […]

Java Date,使用特定日光模式渲染

我有一个Java Date ,从夏天开始,在夏令时期间。 例如: 2009年6月1日上午06:00太平洋时间 我的问题是,如何将此日期显示为当地时区和当前夏令时模式 (在我的太平洋标准时间内)? 2009年6月1日太平洋标准时间05:00 Java的Date.toString()和SimpleDateFormat以原始夏令时模式显示日期。 例: System.out.println(new Date(1243861200000L)); 输出: Mon Jun 01 06:00:00 PDT 2009 DateFormat dateFormat = new SimpleDateFormat(“MMM dd, yyyy hh:mm aa zzz”); dateFormat.setTimeZone(TimeZone.getTimeZone(“PST”)); System.out.println(dateFormat.format(new Date(1243861200000L))); 输出: 2009年6月1日上午06:00太平洋时间 我真正想看的是太平洋标准时间凌晨5点(相当于太平洋夏令时上午6点)。 有没有办法强迫它使用另一种夏令时模式? 跟进:顺便说一下,这是Windows XP的行为。 6月1日上午6点创建的文件(由资源管理器,命令提示符等)将在6月1日冬季凌晨5点出现。

当我们点击不同的按钮时,其内容会发生变化的JFrame

我在这里使用Java’s Swing来制作UI应用程序。 我有一个创建了一个JFrame,带有一些按钮。 当我点击这个按钮时,我想要一个在这个地方有一些不同内容的新JFrame。 但是,我不想在这里加载新的JFrame。 我知道一种方法是在第一个JFrame中按钮的actionPerformed(ActionEvent obj)方法中将第二个JFrame的可见性设置为True。 但它再次加载一个新的JFrame,我不希望这样。 public class FirstUI extends JFrame { JButton but1; public FirstUI(){ but1= new JButton(“Click here”); add(but1); XYZ obj= new XYZ(): but1.addActionListener(obj); } public class XYZ implements ActionListener{ public void actionPerformed(ActionEvent obj1){ // WHAT TO DO HERE } } } 我只想要一个JFrame,当我们点击不同的按钮时,其内容会发生变化。 我怎样才能做到这一点?

Android错误:应用程序意外停止请再试一次

我做了一个工作正常的应用程序。 它显示应用程序启动的次数。 这是代码: import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.widget.TextView; public class PreferencesDemo extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Get the app’s shared preferences SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this); // Get the value for the run counter int […]

在弹性搜索高级客户端中为JAVA添加身份validation

我在使用X-PACK保护的弹性云实例中使用了弹性搜索实例。 我以前一直在使用高级rest客户端没有任何问题,但我无法找到如何发送基本身份validation标头。 我试图将凭据作为URL的一部分,但在这种情况下它似乎无法连接。 有没有人成功连接到高级rest客户端的安全弹性搜索? 干杯,

尽管使用了@Primary,但两个具有相同名称的bean会导致ConflictingBeanDefinitionException

我有一个应用程序初始化程序类,用于将特定于应用程序的数据插入数据库。 @Component(“applicationInitializer”) public class ApplicationInitializer { @PostConstruct public void init(){ // some clever code here } } 还有DevApplicationInitializer类,用于在开发人员计算机上使用一些示例数据初始化数据库(在部署生产代码时排除此类)。 @Component(“applicationInitializer”) @Primary public class DevApplicationInitializer extends ApplicationInitializer { @PostConstruct @Override public void init(){ super.init(); // even more clever code here } } 直到我给bean命名(只有@Component注释) – 一切正常 – 当DevApplicationInitializer可用时,它被实例化而不是ApplicationInitializer 。 当我给他们一个applicationInitializer名称时,抛出了exception: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name ‘applicationInitializer’ for bean class […]

@Transactional如何影响Hibernate中的当前会话?

这是大多数DAO中使用的典型设置: @Transactional @Repository public class DAO { @Autowired SessionFactory sessionFactory; public void save(Entity o) { sessionFactory.getCurrentSession().save(o); } public Entity load(int id) { return (Entity)sessionFactory.getCurrentSession().get(Entity.class, id); } } 我看到只调用了getCurrentSession() ,没有openSession或者close 。 因此,当我从load返回实体时,它不在会话中,懒惰的集合无法加载。 同样,保存似乎总是冲洗! 来自spring的@Transactional注释是否完成了打开和关闭会话和事务的魔力?