小编Shi*_*n-O的帖子

HashSet与LinkedHashSet

他们之间有什么区别?我知道

LinkedHashSet是HashSet的有序版本,它维护所有元素的双向链接列表.在关心迭代顺序时,请使用此类而不是HashSet.当您遍历HashSet时,顺序是不可预测的,而LinkedHashSet允许您按照插入顺序迭代元素.

但是在LinkedHashSet的源代码中,只有HashSet的调用构造函数.那么双链接列表和插入顺序在哪里?

java hashset linkedhashset

148
推荐指数
5
解决办法
11万
查看次数

如何格式化双点?

如何String.format使用整数和小数部分之间的点将Double格式化为String?

String s = String.format("%.2f", price);
Run Code Online (Sandbox Code Playgroud)

以上格式仅使用逗号:",".

java string format double

45
推荐指数
1
解决办法
4万
查看次数

如何在<xs:all>中创建可选项?

我有这样的xsd.这些所有字段都可以存在或不存在,并且不可预测.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

<xs:element name="request">
<xs:complexType>
  <xs:all  minOccurs="0">
    <xs:element ref="field1"/>
    <xs:element ref="field2"/>
    <xs:element ref="field3"/>
    <xs:element ref="field4"/>
    <xs:element ref="field5"/>
  </xs:all>
</xs:complexType>
</xs:element>

</xs:schema>
Run Code Online (Sandbox Code Playgroud)

field4在xml中不存在,验证器说他正在等待field4,但他不应该这样说.那有什么不对?

w3cschools.com

<xs:element name="person">
<xs:complexType>
<xs:all minOccurs="0">
  <xs:element name="firstname" type="xs:string"/>
  <xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)

上面的例子表明"firstname"和"lastname"元素可以按任何顺序出现,每个元素可以出现零次或一次!

xsd

11
推荐指数
1
解决办法
6237
查看次数

DTO的单元测试

测试吸气剂和固定剂是否合适和必要?

我认为他们没有任何逻辑,他们不会崩溃或抛出任何例外.

java unit-testing dto

10
推荐指数
3
解决办法
1万
查看次数

如何在Spring中控制bean init-method调用的顺序?

假设我有bean,应该在另一个bean的init-method之后调用init-method或构造函数.可能吗?

java spring initialization javabeans

9
推荐指数
2
解决办法
1万
查看次数

方法收益如何运作?

在javadoc中有说yield方法

导致当前正在执行的线程对象暂时暂停并允许其他线程执行.

Katherine Sierra和Bert Bates的SCJP书中说过

yield()应该做的是使当前运行的线程返回runnable以允许具有相同优先级的其他线程轮到他们.

那么实际的方法是做什么的?

java multithreading yield

8
推荐指数
1
解决办法
6380
查看次数

Spring框架名称背景

Spring引用Spring Framework意味着什么?我不认为这只是其作者最喜欢的季节)

java spring

8
推荐指数
1
解决办法
1613
查看次数

Mybatis一对多集合映射始终具有一个默认实体

我想重写我们的服务以使用mybatis映射和连接来使我们的实体在数据库/ mybatis层上完整并完成.

<resultMap id="ParentMap" type="org.example.mybatis.Parent">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <id column="Name" jdbcType="VARCHAR" property="name" />
    <id column="SurName" jdbcType="VARCHAR" property="surName" />

    <collection property="childs" column="ChildId"
        javaType="ArrayList" ofType="org.example.mybatis.Child"
        resultMap="org.example.ChildMap" />    
</resultMap>

<resultMap id="ChildMap" type="org.example.mybatis.Parent">

    <id column="id" jdbcType="VARCHAR" property="id" />
    <id column="Name" jdbcType="VARCHAR" property="name" />
    <id column="SurName" jdbcType="VARCHAR" property="surName" />
    <id column="Age" jdbcType="INTEGER" property="age" />
</resultMap>

<sql id="Parent_Column_List">
    p.Id, p.Name, p.SurName,
</sql>  

<sql id="Child_Column_List">
    c.Id, c.ParentId c.Name, c.SurName, c.Age
</sql>  

<select id="getParent" parameterType="java.lang.String" resultMap="ParentMap" >
    select 
    <include refid="Parent_Column_List"/>

    <include refid="Child_Column_List" />
    from Parent p …
Run Code Online (Sandbox Code Playgroud)

java sql spring mybatis

6
推荐指数
1
解决办法
4万
查看次数

Mybatis嵌套集合无法正确使用列前缀

我需要使用mybatis映射为另一个集合中的对象设置集合.

它适用于我没有使用columnPrefix,但我需要它,因为有很多可重复的列.

     <resultMap id="ParentMap" type="org.example.mybatis.Parent">
        <id column="Id" jdbcType="VARCHAR" property="id" />
        <result column="Name" jdbcType="VARCHAR" property="name" />
        <result column="SurName" jdbcType="VARCHAR" property="surName" />

        <collection property="childs"
        javaType="ArrayList" ofType="org.example.mybatis.Child"
        resultMap="ChildMap" columnPrefix="c_"/>       
    </resultMap>

<resultMap id="ChildMap" type="org.example.mybatis.Parent">
    <id column="Id" jdbcType="VARCHAR" property="id" />
    <result column="ParentId" jdbcType="VARCHAR" property="parentId" />
    <result column="Name" jdbcType="VARCHAR" property="name" />
    <result column="SurName" jdbcType="VARCHAR" property="surName" />
    <result column="Age" jdbcType="INTEGER" property="age" />

    <collection property="toys"
        javaType="ArrayList" ofType="org.example.mybatis.Toy"
        resultMap="ToyMap" columnPrefix="t_"/>   
</resultMap>

<resultMap id="ToyMap" type="org.example.mybatis.Toy">
    <id column="Id" jdbcType="VARCHAR" property="id" />
    <result column="ChildId" jdbcType="VARCHAR" property="childId" />
    <result column="Name" jdbcType="VARCHAR" property="name" /> …
Run Code Online (Sandbox Code Playgroud)

java sql spring ibatis mybatis

3
推荐指数
1
解决办法
8740
查看次数