生成增删改查

About the AppFuse Maven Plugin (AMP)

This plugin currently does two things:

For more documentation on this plugin, see its Maven-generated site.

Generating CRUD with AMP

Stop and think before generating code!
At first, I didn't want to add a code-generation feature like this because you end up with a 1-to-1 relationship between tables/pojos, DAOs and Managers. On most of my projects, I have far fewer DAOs and Managers than POJOs.

Using this plugin, you can run the following command to generate CRUD screens/classes for a POJO:

If you don't specify the entity name, you're prompted for it. After generating the code, the plugin will install it for you as well, unless you specify -DdisableInstallation=true. If you disable installation, you can install it using:

To remove the installed artifacts, use:

If your entity is not defined in hibernate.cfg.xml, it will be added. In a modular project, these commands must be run in the "core" and "web" modules. The plugin is smart enough to figure out when it should/should not generate stuff based on the packaging type (jar vs. war).

There's also a goal that allows you to generate model objects from database tables:

Once you've generated and installed the POJO, you can generated crud for it using the appfuse:gen command.

We hope to combine gen and gen-model into a single command.

Customizing AMP Templates

The FreeMarker templates that AMP uses to generate code are packaged in the plugin itself. Since version 2.0.2, you can copy the code generation templates into your project using the following command:

In previous versions, you can customize templates using the following steps:

  1. Checkout the plugin from SVN (username: guest, password: <blank>):
    svn co https://appfuse.dev.java.net/svn/appfuse/trunk/plugins/appfuse-maven-plugin appfuse-maven-plugin
    
  2. Customize the templates in src/main/resources/appfuse.
  3. Run mvn install (use -Dmaven.test.skip=true if tests fail and you don't want to fix them).
  4. Make sure your project matches the version number you just installed.

Installing AppFuse's source into your project

The good news is creating an "old style" project is now pretty easy. If you create a new project using 2.0-m5+, you can now use:

This goal will convert your project to use all of AppFuse's source and remove all dependencies on AppFuse. It will also refactor all package names and directories to match your project's groupId.

What the full-source plugin does:

  1. Exports all sources from Subversion into your project. It reads the dao.framework and web.framework properties to determine what you need.
  2. Removes warpath plugin from pom.xml.
  3. Calculates dependencies by reading pom.xml files form the various AppFuse modules. It replaces your dependencies with these new ones. The order of the dependencies added is alphabetical based on groupId.
  4. Reads properties from the root AppFuse pom.xml and adds the ones that don't exist to your project.
  5. Renames packages to match your project's groupId.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis Plus 是一个开源的 MyBatis 增强工具,它简化了与数据库的交互过程,提供了许多方便易用的功能。下面我将以300字介绍 MyBatis Plus 如何生成增删改查和文件下载的功能。 首先,MyBatis Plus 提供了代码生成器,可以根据数据库表的结构自动生成实体类、Mapper 接口和 XML 映射文件。我们只需要配置好数据库连接和相关参数,运行代码生成器,即可生成基本的增删改查代码。 生成的代码遵循了 MyBatis 的规范,我们可以在生成的实体类中定义表的字段,并使用注解指定与数据库的映射关系。通过继承 MyBatis Plus 提供的 BaseMapper 接口,我们可以轻松地实现基本的增删改查操作,无需手动编写 SQL 语句。 除了基本的增删改查,MyBatis Plus 还提供了一些高级的查询功能。例如,我们可以使用 Wrapper 来构建复杂的查询条件,支持分页查询、排序等。同时,MyBatis Plus 还支持批量操作,可以一次性插入多个实体对象,提高了数据的处理效率。 对于文件下载的功能,我们可以使用 MyBatis Plus 的文件上传下载组件进行处理。通过配置文件上传的目录,我们可以将文件保存到指定的位置。而文件下载则可以通过在 Controller 中编写对应的接口方法,根据文件的路径将文件返回给用户。 总结来说,MyBatis Plus 提供了代码生成器来生成基本的增删改查代码,简化了与数据库的交互。它还支持复杂的查询条件、批量操作和文件上传下载等功能,方便开发者进行数据库操作和文件处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值