在eclipse下使用mybatis时,编写sql的xml没有智能提示还是一件很麻烦的事情,同时在dao层的方法要去映射到xml中的id名,跳转也是一件操作繁琐的事情,最近在eclipse官网发现了一个比较还用的mybatis插件,可以解决我们在使用mybatis时不方便的问题。

插件地址:http://marketplace.eclipse.org/content/mybatipse

XML Editor Enhancements

Auto-completion

  • Mapper namespace : Calculated from the path.
    Mybatis插件-mybatipseMybatis插件-mybatipse
  • Java class/Type alias : Propose Java classes and Type Aliases (translucent icons). Camelcase match is supported. [1] [2]
    Mybatis插件-mybatipseMybatis插件-mybatipse
  • Java property : Propose properties of the parent java class. Nested properties are supported.
    Mybatis插件-mybatipseMybatis插件-mybatipse
  • Statement ID : If corresponding mapper interface exists, propose the method name as a statement ID.
    Mybatis插件-mybatipse
  • Reference to resultMap/select/sql : Propose ID of the referenced resultMap/select/sql. External reference is supported (blue icons).
    Mybatis插件-mybatipse
  • Parameter properties : #{} and ${} in select/insert/udpate/delte statements. Also works in some attributes.
    Mybatis插件-mybatipseMybatis插件-mybatipse
  • javaType, jdbcType, typeHandler in #{}
    Mybatis插件-mybatipse
  • Result elements in resultMap/collection/association : Generates elements for the parent java class properties.
    Mybatis插件-mybatipseMybatis插件-mybatipse

  • [1] For better performance, classes in the application libraries (loaded as JARs) are listed only when at least one package segment is specified.

  • [2] There is a limitation for the type alias support. Basically, if type aliases are registered using Java API, they are not automatically detected. As a workaround, you can register type aliases in MyBatipse's preference. See the Configuration section.

Hyperlinks

  • To referenced resultMap/select/sql element. External reference is supported.
  • To mapper interface method.

Validation

  • Missing TypeAlias, Java class/property.
  • Missing resultMap/select/sql ID.
  • etc.
    Mybatis插件-mybatipseMybatis插件-mybatipse

Java Editor Enhancements

Auto-completion

  • Parameter properties : #{} and ${} in select/insert/udpate/delte annotations. Mybatis插件-mybatipse
  • javaType, jdbcType, typeHandler in #{} : See the XML example.
  • Reference to resultMap in @ResultMap
    Mybatis插件-mybatipse

Quick Assist

  • Add @Param to method parameters : Put the cursor on the method name and press cmd + 1 (or ctrl + 1).
    Mybatis插件-mybatipse
    Mybatis插件-mybatipse

Configuration

MyBatis Nature

  • By default, each file is validated when it's saved, but you would want to validate the XML mapper when the related Java classes are updated as well. For that purpose, MyBatipse provides a custom nature MyBatis Nature.
    To add the nature, right click the project in the package explorer and choose Configure -> Add MyBatis Nature from the menu.
    Mybatis插件-mybatipse

Type Alias

  • Type alias are automatically detected if they are registered using XML config file (both mybatis and mybatis-spring config is supported).
    If you register type aliases in Java code, MyBatipse cannot detect them. As a workaround, you can register custom type aliases in the project setting (Open Project -> Properties menu and select MyBatipse from the left column).
    Mybatis插件-mybatipse
    For example, with the above settings:
    • The first entry registers all the classes in com.example.domain package as type aliases.
    • The second entry registers the single class domain.Person.
    • The third entry registers the single class domain.SomeLongNamedBean under the alias SomeBean.
    • Note that, in any case, MyBatipse respects @Alias annotation if it exists.

Tips

  • To move MyBatis proposals to the top of the XML proposal list, quit Eclipse and open the following file in the workspace: .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.xml.ui.prefs Find the line started with xml_content_assist_default_page_sort_order= and insertnet.harawata.mybatis.proposalCategory.xml\u0000 right after the equal sign.
    Mybatis插件-mybatipse

相关文章:

  • 2021-06-21
  • 2022-01-26
  • 2022-02-27
  • 2021-07-16
  • 2022-01-31
  • 2021-08-27
  • 2022-01-22
  • 2022-12-23
猜你喜欢
  • 2021-08-09
  • 2022-01-05
  • 2021-11-14
  • 2021-12-31
  • 2022-02-13
相关资源
相似解决方案