目标
在清晨的代码编辑器上,一场新的挑战即将开始。程序员们肃立于安静的办公室,眼神专注地盯着屏幕,等待着编译器的一声提示。
随着编译器输出的激动人心的"start!"的提示,战斗的序幕拉开了。Bug如潮水般涌来,程序员们快速调整键盘,代码在屏幕上飞速滚动,IDE中的光标如箭一般穿梭,指引着他们找出每一个漏洞。代码的碰撞声、键盘的敲击声、鼠标的点击声交织成一曲激烈的交响乐,扣人心弦。
在这个混乱的调试中,每个程序员都展现出顶尖的技艺与冷静的勇气。他们忘我地追踪Bug,代码间的逻辑错综复杂,他们努力理清每一行代码的错误,誓言修复每一个漏洞。长时间的疲劳和思考在他们身上无处不在,但他们坚定不移,因为他们知道,这场战斗不仅仅是为了完成任务,更是为了程序的稳定与优化。
随着代码的逐步修复,胜利的曙光逐渐浮现。Bug一个个被排除,程序稳定运行,最终的"Deploy Successful!"的消息如太阳升起,标志着任务的完成和程序的成功运行。
这场战斗,不仅仅是一场技术上的挑战,更是一场耐心与智慧的考验。他们用思维与代码铸就了成功的光辉,为了项目的顺利进行,为了自己对技术的追求与信仰,他们勇敢地战斗着
开始挑战
打开idea
创建Spring项目
依赖就选springweb
创建完成首先在xml文件里配置依赖
<?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><groupId>com.bigdata1421</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><name>demo</name><description>demo</description><properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><spring-boot.version>2.6.13</spring-boot.version></properties><dependencies><!-- lombok 快速封装实体类--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><!-- mybatis-plus 快速数据层开发--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.3</version></dependency><!-- druid数据库连接池--><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.6</version></dependency><!-- mysql驱动--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>runtime</version></dependency><!-- web应用内嵌服务器--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- springboot起步依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>${spring-boot.version}</version><configuration><mainClass>com.example.demo.DemoApplication</mainClass><skip>true</skip></configuration><executions><execution><id>repackage</id><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>
接着配置数据库连接信息
server:port: 80spring:datasource:druid:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTCusername: rootpassword: 123456# 配置mybatis-plus
mybatis-plus:global-config:db—config:table-prefix: tbl_
接下来
用lombok快速封装实体类
package com.example.demo.domain;import lombok.Data;@Data
public class User {private String id;private String name;private String age;private String gender;
}
用Mybatis-plus开发数据层接口
package com.example.demo.dao;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.domain.User;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface UserDao extends BaseMapper<User> {
}
开发业务层
面向接口编程
先在接口定义了五个方法
package com.example.demo.service;import com.example.demo.domain.User;import java.util.List;public interface UserService {public boolean save(User user);public User getById(Integer id);public boolean update(User user);public boolean delete(Integer id);public List<User> getAll();}
书写实现类
在注入数据层接口的同时
重写业务层方法
package com.example.demo.service.impl;import com.example.demo.dao.UserDao;
import com.example.demo.domain.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class UserServiceImpl implements UserService {@Autowiredprivate UserDao userDao;@Overridepublic User getById(Integer id) {return userDao.selectById(id);}@Overridepublic boolean save(User user) {return userDao.insert(user)>0;}@Overridepublic boolean update(User user) {return userDao.updateById(user)>0;}@Overridepublic boolean delete(Integer id) {return userDao.deleteById(id)>0;}@Overridepublic List<User> getAll() {return userDao.selectList(null);}
}
创建控制器
controller层MVC类
与前端页面进行交互
package com.example.demo.controller;import com.example.demo.domain.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;@RestController
@RequestMapping("/users")
public class UserController {//注入业务层@Autowiredprivate UserService userService;//规定请求方式@GetMappingpublic List<User> getAll(){return userService.getAll();}@PostMappingpublic Boolean save(@RequestBody User user){return userService.save(user);}@PutMappingpublic Boolean update(@RequestBody User user){return userService.update(user);}@DeleteMapping("{id}")public Boolean delete(@PathVariable Integer id){return userService.delete(id);}@GetMapping("{id}")public User getById(@PathVariable Integer id){return userService.getById(id);}}
这样一个基本的框架就已经完成
我们把springboot项目启动起来
我们这时候到postman里
发起请求 去进行一个查询
成功查询
挑战成功
耗时4分49秒!
爽
个人号推广
博客主页
多多!-CSDN博客
Web后端开发
https://blog.csdn.net/qq_30500575/category_12624592.html?spm=1001.2014.3001.5482
Web前端开发
https://blog.csdn.net/qq_30500575/category_12642989.html?spm=1001.2014.3001.5482
数据库开发
https://blog.csdn.net/qq_30500575/category_12651993.html?spm=1001.2014.3001.5482
项目实战
https://blog.csdn.net/qq_30500575/category_12699801.html?spm=1001.2014.3001.5482
算法与数据结构
https://blog.csdn.net/qq_30500575/category_12630954.html?spm=1001.2014.3001.5482
计算机基础
https://blog.csdn.net/qq_30500575/category_12701605.html?spm=1001.2014.3001.5482
回忆录
https://blog.csdn.net/qq_30500575/category_12620276.html?spm=1001.2014.3001.5482