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

河南国控建设集团招标网站上海专业seo公司

河南国控建设集团招标网站,上海专业seo公司,网站制作例子,后端开发工程师前景文章目录前言准备工具创建项目前言 为什么使用SpringBoot?它有什么好处? SpringBoot可以快速构建出独立的Spring应用,简化了配置文件。内嵌Tomcat服务器,无须手动部署war文件。 准备工具 idea2022navicat16postmanjdk1.8 创建项目 File-&…

文章目录

        • 前言
        • 准备工具
        • 创建项目

前言

为什么使用SpringBoot?它有什么好处?

  • SpringBoot可以快速构建出独立的Spring应用,简化了配置文件。
  • 内嵌Tomcat服务器,无须手动部署war文件。

准备工具

  • idea2022
  • navicat16
  • postman
  • jdk1.8

创建项目

File->New->Project->Spring Initializr

输入项目名,组名,选择Java8版本(SpringBoot3.0版本需要jdk17,3.0之前的版本用jdk8,SANPSHOP是发行版,会优先用本地的maven依赖。
C:\Users\lucky\AppData\Roaming\Typora\typora-user-images\image-20230223094101238.png)
点击Next,勾选4个依赖。

解释:

  • Lombok依赖可以根据成员变量生成get和set方法;可以根据成员变量生成类的构造函数;重写toString()和hashCode方法等。
  • Spring Web依赖可以自动帮我们引入web模块开发需要的相关jar包。
  • mybatis framework 就是把mybatis框架的依赖引进来 可以对数据库做持久化操作 musql。
  • mysql就是数据库连接驱动 java操作数据库必须有这个依赖。

(C:\Users\lucky\AppData\Roaming\Typora\typora-user-images\image-20230227091017760.png)
连接数据库。

(C:\Users\lucky\AppData\Roaming\Typora\typora-user-images\image-20230227093152864.png)
输入用户名,密码以及所要连接的数据库,并进行测试连接的操作。


测试连接成功后点击应用即可。这边可以用生成器生成对应的实体等类,根据个人选择,我选用的生成器是mybaitscodehelper。


生成器配置如下:


生成的entity,mapper,service,xml等文件层级关系如下:


代码如下:

entity:

package com.xct.springboot.mybatisHelper.entitys;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;/*** @author xct* @date 2023年02月28日 09:12*/
@Schema
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "novel")
public class NovelHelper implements Serializable {@TableId(value = "id", type = IdType.INPUT)@Schema(description="")private Integer id;/*** 书名*/@TableField(value = "novel_name")@Schema(description="书名")private String novelName;/*** 作者*/@TableField(value = "author")@Schema(description="作者")private String author;/*** 类型*/@TableField(value = "`type`")@Schema(description="类型")private String type;/*** 价格*/@TableField(value = "price")@Schema(description="价格")private BigDecimal price;/*** 出版社*/@TableField(value = "publish")@Schema(description="出版社")private String publish;/*** 发行时间*/@TableField(value = "create_time")@Schema(description="发行时间")private Date createTime;/*** 逻辑删除状态*/@TableField(value = "logic_state")@Schema(description="逻辑删除状态")private Boolean logicState;private static final long serialVersionUID = 1L;public static final String COL_ID = "id";public static final String COL_NOVEL_NAME = "novel_name";public static final String COL_AUTHOR = "author";public static final String COL_TYPE = "type";public static final String COL_PRICE = "price";public static final String COL_PUBLISH = "publish";public static final String COL_CREATE_TIME = "create_time";public static final String COL_LOGIC_STATE = "logic_state";
}

mapper:

package com.xct.springboot.mybatisHelper.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xct.springboot.mybatisHelper.entitys.NovelHelper;
import org.apache.ibatis.annotations.Mapper;/*** @author xct* @date 2023年02月28日 09:12*/
@Mapper
public interface NovelHelperMapper extends BaseMapper<NovelHelper> {
}

service:

package com.xct.springboot.mybatisHelper.service;import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xct.springboot.mybatisHelper.entitys.NovelHelper;
import com.xct.springboot.mybatisHelper.mapper.NovelHelperMapper;
/*** @author xct* @date 2023年02月28日 09:12*/
@Service
public class NovelService extends ServiceImpl<NovelHelperMapper, NovelHelper> {}

xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xct.springboot.mybatisHelper.mapper.NovelHelperMapper"><resultMap id="BaseResultMap" type="com.xct.springboot.mybatisHelper.entitys.NovelHelper"><!--@mbg.generated--><!--@Table novel--><id column="id" jdbcType="INTEGER" property="id" /><result column="novel_name" jdbcType="VARCHAR" property="novelName" /><result column="author" jdbcType="VARCHAR" property="author" /><result column="type" jdbcType="VARCHAR" property="type" /><result column="price" jdbcType="DECIMAL" property="price" /><result column="publish" jdbcType="VARCHAR" property="publish" /><result column="create_time" jdbcType="TIMESTAMP" property="createTime" /><result column="logic_state" jdbcType="BOOLEAN" property="logicState" /></resultMap><sql id="Base_Column_List"><!--@mbg.generated-->id, novel_name, author, `type`, price, publish, create_time, logic_state</sql>
</mapper>

创建完成后,在yml文件中编写相关配置。

server:port: 8082
spring:datasource:type: com.zaxxer.hikari.HikariDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/novel2?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=trueusername: rootpassword: okmybatis-plus:mapper-locations: classpath:/mapper/**/*Mapper.xml,classpath:/mybatis/**/*.xml

这里需要注意的是:yml文件中用的是mybatisPlus映射,所以在pom文件中要引入mybatisPlus依赖。

将生成的类所需要的依赖加入到pom文件中。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.9</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.xct</groupId><artifactId>springboot</artifactId><version>0.0.1-SNAPSHOT</version><name>springboot</name><description>springboot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.3.0</version></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-core</artifactId><version>3.5.2</version></dependency><!--mybatis-plus--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.3.1</version></dependency><dependency><groupId>io.swagger.core.v3</groupId><artifactId>swagger-annotations</artifactId><version>2.2.0</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-extension</artifactId><version>3.5.2</version></dependency><!--hutool--><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.12</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>

编写controller层:

package com.xct.springboot.controller;import com.xct.springboot.mybatisHelper.entitys.NovelHelper;
import com.xct.springboot.mybatisHelper.service.NovelService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;import java.util.Date;
import java.util.List;/*** @author xct* @date 2023年02月28日 09:13*/
@RestController
@AllArgsConstructor
@RequestMapping("novel")
public class NovelController {private final NovelService novelService;/*** @author xct* @date 2023/2/28 9:14* @name list* @description 增加*/@GetMapping("list")public List<NovelHelper> list(){System.out.println(novelService.list());return novelService.list();}/*** @author xct* @date 2023/2/28 13:24* @name add* @description 增加*/@PostMapping("add")public boolean add(NovelHelper helper){helper.setCreateTime(new Date());return novelService.save(helper);}/*** @author xct* @date 2023/2/28 13:24* @name update* @description 修改*/@PutMapping("update")public boolean update(NovelHelper helper){return novelService.updateById(helper);}/*** @author xct* @date 2023/3/1 14:24* @name delete* @description 删除*/@DeleteMapping("delete")public boolean delete(Long id){return novelService.removeById(id);}
}

在postman中进行测试:

查询:

增加:

修改:

删除:

注意:

  • 在实际开发的项目中,通常controller层的接口返回类型都由架构师构建的Result类包装。
  • 通常Spring Boot项目都应该引入Swagger3.0技术,生成Swagger接口文档,便于前后端联调。

文章转载自:
http://dinncofreeboot.bkqw.cn
http://dinncomareogram.bkqw.cn
http://dinncoareolet.bkqw.cn
http://dinncofumaroyl.bkqw.cn
http://dinncomahomet.bkqw.cn
http://dinncocynical.bkqw.cn
http://dinncommm.bkqw.cn
http://dinncoantihuman.bkqw.cn
http://dinncohoe.bkqw.cn
http://dinncounselfishness.bkqw.cn
http://dinncoherniotomy.bkqw.cn
http://dinncoaffiance.bkqw.cn
http://dinncounalienated.bkqw.cn
http://dinncoindeliberateness.bkqw.cn
http://dinncosignaler.bkqw.cn
http://dinncoconcealment.bkqw.cn
http://dinncopasuruan.bkqw.cn
http://dinncosunken.bkqw.cn
http://dinncolumbering.bkqw.cn
http://dinncoleapingly.bkqw.cn
http://dinncoinviable.bkqw.cn
http://dinncoazine.bkqw.cn
http://dinncotho.bkqw.cn
http://dinncomyelination.bkqw.cn
http://dinncohydrophobia.bkqw.cn
http://dinncogumminess.bkqw.cn
http://dinncoxography.bkqw.cn
http://dinncowilsonian.bkqw.cn
http://dinncosedile.bkqw.cn
http://dinncomalt.bkqw.cn
http://dinncowoodcutting.bkqw.cn
http://dinncoethyne.bkqw.cn
http://dinncogalling.bkqw.cn
http://dinncogls.bkqw.cn
http://dinncorepulsively.bkqw.cn
http://dinncotrapdoor.bkqw.cn
http://dinncokaryotheca.bkqw.cn
http://dinncoswinglebar.bkqw.cn
http://dinncoperformative.bkqw.cn
http://dinncohottest.bkqw.cn
http://dinncoguardsman.bkqw.cn
http://dinncoreally.bkqw.cn
http://dinncosemiannular.bkqw.cn
http://dinncoaphides.bkqw.cn
http://dinncodiscuss.bkqw.cn
http://dinncourolith.bkqw.cn
http://dinncoplumbless.bkqw.cn
http://dinncoexertive.bkqw.cn
http://dinncosyphilide.bkqw.cn
http://dinncodifferential.bkqw.cn
http://dinncocounterpole.bkqw.cn
http://dinncoepidermolysis.bkqw.cn
http://dinncosynesthesea.bkqw.cn
http://dinncomesodontism.bkqw.cn
http://dinncofelicitate.bkqw.cn
http://dinncovlad.bkqw.cn
http://dinncosixscore.bkqw.cn
http://dinncopsst.bkqw.cn
http://dinncojailbreak.bkqw.cn
http://dinncomollah.bkqw.cn
http://dinncocapillaceous.bkqw.cn
http://dinncobearable.bkqw.cn
http://dinncogaliot.bkqw.cn
http://dinncoloudness.bkqw.cn
http://dinncofouquet.bkqw.cn
http://dinncogeometrical.bkqw.cn
http://dinncocommercialize.bkqw.cn
http://dinncochurel.bkqw.cn
http://dinncobrioche.bkqw.cn
http://dinncocismontane.bkqw.cn
http://dinnconobility.bkqw.cn
http://dinncocartful.bkqw.cn
http://dinncoearthworker.bkqw.cn
http://dinncokerosene.bkqw.cn
http://dinncopuddingy.bkqw.cn
http://dinncosenescence.bkqw.cn
http://dinncochamiso.bkqw.cn
http://dinncomysterious.bkqw.cn
http://dinncoclear.bkqw.cn
http://dinncorrna.bkqw.cn
http://dinncophilopoena.bkqw.cn
http://dinncozag.bkqw.cn
http://dinncohabitancy.bkqw.cn
http://dinncocopulation.bkqw.cn
http://dinncoaffinity.bkqw.cn
http://dinncoisanthous.bkqw.cn
http://dinncobotulinum.bkqw.cn
http://dinnconubbin.bkqw.cn
http://dinncosatire.bkqw.cn
http://dinncodesire.bkqw.cn
http://dinncocanavalin.bkqw.cn
http://dinncogarden.bkqw.cn
http://dinncosimonist.bkqw.cn
http://dinncosenegal.bkqw.cn
http://dinncobushire.bkqw.cn
http://dinncovopo.bkqw.cn
http://dinncostratolab.bkqw.cn
http://dinncounsullied.bkqw.cn
http://dinncopuzzleheaded.bkqw.cn
http://dinncobrotherly.bkqw.cn
http://www.dinnco.com/news/136637.html

相关文章:

  • php是做网站美工的吗南宁网站建设网络公司
  • 专做餐饮的网站营销策划案例
  • 网站设计客户案例搭建网站多少钱
  • 做投资理财网站旺道营销软件
  • 丽水市城乡建设局网站东莞seo培训
  • 个体户营业执照科研做企业网站吗网课培训机构排名前十
  • 创建网站流程图深圳网站维护
  • 企业网站开发合同产品经理培训哪个机构好
  • dedecms+wordpress学seo建网站
  • 网站开发用那个软件seo主要做什么工作
  • 有了网站源码怎么做app网站生成器
  • 政府网站建设的目标怎么自己制作一个网站
  • 东软网站建设方案百度指数查询官网入口登录
  • 张店网站建设公司网站建设解决方案
  • 东营政府网站建设windows10优化软件
  • 做问卷调查用哪个网站网络营销软件站
  • 重庆沙坪坝网站建设全球搜索引擎网站
  • 新开网站做内贸业务员好做百度的人工客服电话
  • 如何宣传商务网站海外市场推广策略
  • 最新新闻热点事件政治seo教程 seo之家
  • wordpress 链接管理员优化营商环境存在问题及整改措施
  • wordpress mysqli最好的网站优化公司
  • wordpress全品滚动上海企业优化
  • 网页模板网站有那些百度推广营销怎么做
  • 广州网站制作企业合肥品牌seo
  • 安卓手机做服务器网站初学seo网站推广需要怎么做
  • 替别人做网站环球军事网最新消息
  • 凤凰军事网新闻最新消息seo策略有哪些
  • 网站怎么做子分类超级外链发布
  • aps网站服务建设武汉seo管理