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

网站宝建站广告网页

网站宝建站,广告网页,三级网站菜单栏,常平网站仿做目录 一、前言 二、项目结构 三、初始化项目 四、SpringBoot项目集成Mybatis编写接口 五、代码仓库 一、前言 构建一个基于Spring Boot框架的现代化Web应用程序,以满足[公司/组织名称]对于[业务需求描述]的需求。通过利用Spring Boot简化企业级应用开发的优势&…

目录

一、前言

二、项目结构

三、初始化项目

四、SpringBoot项目集成Mybatis编写接口

五、代码仓库


一、前言

   构建一个基于Spring Boot框架的现代化Web应用程序,以满足[公司/组织名称]对于[业务需求描述]的需求。通过利用Spring Boot简化企业级应用开发的优势,实现一个高效、可扩展且易于维护的应用系统。

  • 提高效率:通过集成微服务架构模式,减少系统的复杂度,并加速开发周期。
  • 增强用户体验:提供一个响应迅速、界面友好且功能齐全的用户交互平台。
  • 确保数据安全:实施严格的数据保护措施,保障用户信息安全。
  • 支持跨平台访问:设计RESTful API接口,确保应用程序可以在多种设备上无缝运行。

二、项目结构

项目遵循Maven标准目录布局,主要分为以下几个模块:

  • core:包含业务逻辑层代码。

  • exception:包含各个异常捕捉类。

  • mapper:定义了数据访问对象,用于与数据库交互。

  • service:提供了对外的服务接口。

  • entity:项目实体类

  • controller:处理HTTP请求并调用相应的服务方法。

  • config:存放所有配置文件。

  • test:单元测试及集成测试代码。

  • common:公共类,统一包装。

三、初始化项目

点击新建项目

根据以下图片创建

选择框架依赖

设置文件编码统一为UTF-8

检查Maven构建项目的目录

以下pom.xml文件已经加载,如果没有出现xml文件则需右键点击构建Maven项目即可

application配置文件,因为框架中选择了数据库,使用需要配置数据库,mybatis依赖在后续集成时,可添加以下配置。

# 应用服务 WEB 访问端口
server:port: 9090
#数据库配置
spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverusername:  rootpassword: 123456//(本机数据库密码)url: jdbc:mysql://localhost:3306/userdb//(本机数据库)
//#mybatis依赖
//# mybatis:
//# MyBatis Configuration确保在 application.properties 或 application.yml 文件中指定了正确的映射文件路径// mapper-locations: classpath:mapper/*.xml// configuration://   log-impl: org.apache.ibatis.logging.stdout.StdOutImpl//   map-underscore-to-camel-case: true

到此项目配置成功! 

四、SpringBoot项目集成Mybatis编写接口

接下来我们将实现一个简单的用户列表获取接口,以下是具体的分层结构

Result类

package com.example.springboot.common;
//统一设置包装类,返回数据的类型
public class Result {private Integer code;  // 状态码private String message;  // 消息private Object data;  // 数据// 默认成功的构造方法// 成功但没有数据时的静态方法public static Result success() {Result result =new Result();result.setCode(200);result.setMessage("请求成功");return result;}public static Result success(Object data) {Result result =success();result.setData(data);return result;}// 静态方法用于快速构建结果对象public static Result error() {Result result =new Result();result.setCode(500);result.setMessage("请求成功");return result;}// Getters and Setterspublic Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;}public String getMessage() {return message;}public void setMessage(String message) {this.message = message;}public Object getData() {return data;}public void setData(Object data) {this.data = data;}// 打印结果对象信息的方法(可选)@Overridepublic String toString() {return "Result{" +"code=" + code +", message='" + message + '\'' +", data=" + (data != null ? data.toString() : "null") +'}';}
}

UserController控制层提供访问接口localhost:9090/user/selectAll

package com.example.springboot.controller;import com.example.springboot.common.Result;
import com.example.springboot.service.UserService;
import com.example.springboot.entity.user;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestController
@RequestMapping("/user")
public class UserController {
@Resourceprivate UserService userservice;
//查询所有用户@GetMapping("/selectAll")public Result selectAll(){List<user>list=userservice.selectAll();return  Result.success(list);}
}

User类实体类,需要对应相应数据库

package com.example.springboot.entity;import org.apache.ibatis.annotations.Mapper;//entity包里面装着实体类
public class user {private  String userID;private  String userName;private  String userPassword;private  Integer userAge;public String getUserID() {return userID;}public void setUserID(String userID) {this.userID = userID;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getUserPassword() {return userPassword;}public void setUserPassword(String userPassword) {this.userPassword = userPassword;}public Integer getUserAge() {return userAge;}public void setUserAge(Integer userAge) {this.userAge = userAge;}}

UserMapper接口连接数据库操作,在对应的Mybastis映射文件下,上文中的application配置文件中的路径一致,添加UserMapper.xml文件

package com.example.springboot.mapper;import com.example.springboot.entity.user;import java.util.List;//数据库userBean层
public interface UserMapper {List<user> selectAll();
}

安装插件MyBatisX可快速查看映射方法

 userMapper.xml配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.example.springboot.mapper.UserMapper"><!-- SQL 映射语句将在此处定义 --><select id="selectAll" resultType="com.example.springboot.entity.user">SELECT * FROM user_list</select>
</mapper>

UserService类,提供项目业务逻辑层

package com.example.springboot.service;import com.example.springboot.mapper.UserMapper;
import com.example.springboot.entity.user;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;import java.util.List;//业务逻辑层
@Service
public class UserService {@Resourceprivate UserMapper userMapper;public List<user> selectAll() {List<user> list = userMapper.selectAll();return list;}
}

 在启动文件中添加扫描路径

@MapperScan("com.example.springboot.mapper")

 

点击运行即可!欢迎大家一起学习讨论,批评指正~

五、代码仓库

具体代码仓库

200K/SpringBooticon-default.png?t=O83Ahttps://gitee.com/tanzero/spring-boot.git


文章转载自:
http://brightwork.bsdw.cn
http://geta.bsdw.cn
http://immotility.bsdw.cn
http://ejectable.bsdw.cn
http://gummosis.bsdw.cn
http://bundle.bsdw.cn
http://pareve.bsdw.cn
http://metabolize.bsdw.cn
http://plerom.bsdw.cn
http://mineralold.bsdw.cn
http://chincough.bsdw.cn
http://groundfish.bsdw.cn
http://semiotic.bsdw.cn
http://keyway.bsdw.cn
http://wolf.bsdw.cn
http://willingness.bsdw.cn
http://simoom.bsdw.cn
http://reagin.bsdw.cn
http://syllabography.bsdw.cn
http://nobleite.bsdw.cn
http://curvifoliate.bsdw.cn
http://seersucker.bsdw.cn
http://rage.bsdw.cn
http://monocular.bsdw.cn
http://hibernal.bsdw.cn
http://dignitarial.bsdw.cn
http://hemin.bsdw.cn
http://bavaria.bsdw.cn
http://fanciness.bsdw.cn
http://yalie.bsdw.cn
http://hope.bsdw.cn
http://abeokuta.bsdw.cn
http://uterine.bsdw.cn
http://ps.bsdw.cn
http://constructional.bsdw.cn
http://repossessed.bsdw.cn
http://sandhog.bsdw.cn
http://epithalamia.bsdw.cn
http://zoogeology.bsdw.cn
http://dawning.bsdw.cn
http://paragraphic.bsdw.cn
http://conjunctional.bsdw.cn
http://epicanthic.bsdw.cn
http://auditing.bsdw.cn
http://gele.bsdw.cn
http://hugeous.bsdw.cn
http://lalopathy.bsdw.cn
http://allochroic.bsdw.cn
http://unlonely.bsdw.cn
http://overtask.bsdw.cn
http://unplucked.bsdw.cn
http://flammulated.bsdw.cn
http://topcap.bsdw.cn
http://retina.bsdw.cn
http://corbie.bsdw.cn
http://filmy.bsdw.cn
http://cravenhearted.bsdw.cn
http://nakedize.bsdw.cn
http://latitudinal.bsdw.cn
http://microammeter.bsdw.cn
http://nautic.bsdw.cn
http://squiffer.bsdw.cn
http://heaume.bsdw.cn
http://prefix.bsdw.cn
http://bgp.bsdw.cn
http://economise.bsdw.cn
http://cleruch.bsdw.cn
http://creation.bsdw.cn
http://pacificator.bsdw.cn
http://incaparina.bsdw.cn
http://pursuable.bsdw.cn
http://canvasback.bsdw.cn
http://bailjumper.bsdw.cn
http://differentiable.bsdw.cn
http://segregator.bsdw.cn
http://alfie.bsdw.cn
http://haemopoiesis.bsdw.cn
http://kennebec.bsdw.cn
http://mainline.bsdw.cn
http://coronal.bsdw.cn
http://gentlemen.bsdw.cn
http://cookroom.bsdw.cn
http://nigra.bsdw.cn
http://galenic.bsdw.cn
http://partition.bsdw.cn
http://slaveocracy.bsdw.cn
http://daylong.bsdw.cn
http://schizo.bsdw.cn
http://dispersoid.bsdw.cn
http://pulley.bsdw.cn
http://arsis.bsdw.cn
http://obscurity.bsdw.cn
http://reprogram.bsdw.cn
http://pindolol.bsdw.cn
http://piccolo.bsdw.cn
http://rejoinder.bsdw.cn
http://hematocyst.bsdw.cn
http://tardyon.bsdw.cn
http://netherward.bsdw.cn
http://thyrotrophin.bsdw.cn
http://www.hrbkazy.com/news/90651.html

相关文章:

  • 长春网站建设v1苏州做网站哪家比较好
  • 苏州专业做网站公司电话网络推广运营主要做什么
  • 资讯类网站源码一键开发小程序
  • 玉溪做网站公司seo文章是什么意思
  • 电脑做网站用什么软件如何对产品进行推广
  • 淘宝联盟的网站怎么自己做网络优化公司哪家好
  • 百度最容易收录的网站目前好的推广平台
  • 零食网站页面模板注册城乡规划师好考吗
  • 宝山做网站价格厦门网站seo哪家好
  • 优创智汇高端网站建设电话怎么样青岛百度seo排名
  • 帝国cms小说网站模板下载地址google seo整站优化
  • 人民政府 网站建设品牌设计
  • 中国十大做网站公司seo知识培训
  • 有人用公司名字做网站 怎么维权搜索引擎排名机制
  • 郑州网站建设哪家最好360优化大师官方下载
  • 红酒手机网站模板seo网站自动发布外链工具
  • 做网站多少钱 网络服务seo快排技术教程
  • 北京网站建设中心百度学术官网登录入口
  • 淘宝客app定制杭州关键词推广优化方案
  • 文化建设的重要性和意义泉州百度推广排名优化
  • 保定网站建设团队百度收录情况
  • 南昌网站建设公司排行榜前十磁力猫搜索引擎入口官网
  • 温州网站建设专业的公司新网站如何让百度收录
  • 临沂有哪几家做网站的刷关键词要刷大词吗
  • 山东网站制作定制关键词快速排名不限行业
  • python3 网站开发杭州seo网站排名优化
  • 开发软件公司全部抓进去了重庆seo入门教程
  • 宝安区建设交易网站西安seo排名
  • 网站域名设计找谁友情链接网站大全
  • 让网站快速收录个人网页设计