当前位置: 首页 > news >正文

做一个好的公司网站有什么好处重庆疾控最新通告今天

做一个好的公司网站有什么好处,重庆疾控最新通告今天,南京高固建设公司,网站建设与维护怎么学在Spring Boot项目中使用MyBatis-Plus进行代码逆向生成,可以通过MyBatis-Plus提供的代码生成器来快速生成实体类、Mapper接口、Service接口及其实现类等。以下是一个简单的示例步骤: 代码逆向生成 1.添加依赖: 在pom.xml文件中添加MyBati…

在Spring Boot项目中使用MyBatis-Plus进行代码逆向生成,可以通过MyBatis-Plus提供的代码生成器来快速生成实体类、Mapper接口、Service接口及其实现类等。以下是一个简单的示例步骤:

代码逆向生成 

1.添加依赖

pom.xml文件中添加MyBatis-Plus和代码生成器相关的依赖。

<!-- Spring Boot Starter Data JPA -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- MyBatis-Plus -->
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.7</version>
</dependency>
<!-- MyBatis-Plus Generator -->
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.5.7</version>
</dependency>
<dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.31</version> <!-- 使用合适的版本号 -->
</dependency>
<!-- MySQL 驱动 -->
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.23</version>
</dependency>

2.写代码生成器

创建一个Java类,用于配置和运行代码生成器。

public class CodeGenerator {// 你的数据库连接信息private static final String URL = "jdbc:mysql://localhost:3306/my_db?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC";private static final String USERNAME = "root";private static final String PASSWORD = "123456";public static void main(String[] args) {FastAutoGenerator.create(URL, USERNAME, PASSWORD).globalConfig(builder -> builder.author("xiaochen").outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java").commentDate("yyyy-MM-dd").enableSwagger()).packageConfig(builder -> builder.parent("com.demo").entity("entity").controller("controller").service("service").serviceImpl("service.impl").mapper("mapper").xml("mapper.xml")).strategyConfig(builder -> builder.addInclude("user_test").entityBuilder().enableLombok()).templateEngine(new FreemarkerTemplateEngine()).execute();}
}

3.运行代码生成器

运行CodeGenerator类的main方法,代码生成器将会根据配置生成相应的代码文件。

通过以上步骤,你可以快速生成MyBatis-Plus所需的实体类、Mapper接口、Service接口及其实现类等代码,大大提高开发效率。

续:

当然也可以自定义controller,配置如下:

1.修改controller模板 

将其放在 resources 下的 templates 目录下

package ${package.Controller};import org.springframework.web.bind.annotation.RequestMapping;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import ${package.Entity}.${entity};
<#if generateService>
import ${package.Service}.${table.serviceName};
</#if>
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;/*** <p>* ${table.comment!} 前端 控制器* </p>** @author ${author}* @since ${date}*/
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>@Autowiredprivate ${table.serviceName} ${(table.serviceName?substring(1))?uncap_first};/*** 查询所有*/@GetMappingpublic List<${entity}> getAll() {return ${(table.serviceName?substring(1))?uncap_first}.list();}/*** 根据id查询*/@GetMapping("/{id}")public  ${entity} getById(@PathVariable Long id) {return ${(table.serviceName?substring(1))?uncap_first}.getById(id);}/*** 添加*/@PostMappingpublic boolean add(@RequestBody ${entity} ${entity?uncap_first}) {return ${(table.serviceName?substring(1))?uncap_first}.save(${entity?uncap_first});}/*** 修改*/@PutMapping("/{id}")public boolean update(@PathVariable Integer id, @RequestBody  ${entity} ${entity?uncap_first}) {${entity?uncap_first}.setId(id);return ${(table.serviceName?substring(1))?uncap_first}.updateById(${entity?uncap_first});}/*** 删除*/@DeleteMapping("/{id}")public boolean delete(@PathVariable Long id) {return ${(table.serviceName?substring(1))?uncap_first}.removeById(id);}
}
</#if>

2.在strategyConfig配置中添加如下代码

.controllerBuilder().enableRestStyle().template("templates/controller.java")

 3.测试:

生成效果如下:


/*** <p>*  前端 控制器* </p>** @author xiaochen* @since 2024-07-05*/
@RestController
@RequestMapping("/userTest")
public class UserTestController {@Autowiredprivate IUserTestService userTestService;/*** 查询所有*/@GetMappingpublic List<UserTest> getAll() {return userTestService.list();}/*** 根据id查询*/@GetMapping("/{id}")public  UserTest getById(@PathVariable Long id) {return userTestService.getById(id);}/*** 添加*/@PostMappingpublic boolean add(@RequestBody UserTest userTest) {return userTestService.save(userTest);}/*** 修改*/@PutMapping("/{id}")public boolean update(@PathVariable Integer id, @RequestBody  UserTest userTest) {userTest.setId(id);return userTestService.updateById(userTest);}/*** 删除*/@DeleteMapping("/{id}")public boolean delete(@PathVariable Long id) {return userTestService.removeById(id);}
}

 

http://www.lakalapos1.cn/news/379/

相关文章:

  • 专业网站运营制作优化公司治理
  • 电商网站开源授权二次开发学院网站建设目的与意义
  • 河北中小企业网站wordpress 分类 图标
  • 网站备案提交管局做营销的一般逛哪些网站
  • 北京市建设网站首页齐鲁人才网泰安招聘
  • 手机网站图片做多大北京安卓app开发公司
  • 重庆建企业网站中国建设网查询平台网址
  • 罗夫曼三大社区模式网站优化计划
  • 深圳的网站建设公司那家好外包的企业网站
  • 云南企业网站建设百度网址导航
  • 玫琳凯网站建设与推广方案网络营销的四种策略
  • 网站建设文库 新的开始网站美工设计收费
  • 菜鸟必读 网站被入侵后需做的检测 1昆山新宇网站建设
  • 网站推广seo优化seo推广官网
  • 如何利用阿里云做网站企业建立网站的必要性在于
  • 策划公司取名字大全搜索引擎优化 简历
  • 人工智能ai写作网站免费做购物网站
  • html5网站开发技术做网站翻页怎么做
  • 凡高网站建设wordpress照片墙
  • 教人做美食视频网站wordpress评论分页不显示
  • 网站营销推广方案官方网站下载官方版本
  • 玫琳凯网站建设方案网站设计内容清单
  • 深圳网站建设 利科技有限公司常德网红
  • 一个网站如何做桌面快捷链接gta5显示网站建设中
  • 海南省住房公积金管理局网站做网站seo
  • 中国空间站视频做网站前景怎么样
  • 网站开发语言选择公众号制作用什么软件
  • 403.14网站购物网站如何建设
  • 全国免费自学网站有哪些朝阳网络公司怎么样
  • 滕建建设集团网站大庆市建设中专网站