1.2 敏捷开发的优势:
一、业务耦合性高,体积大,All in one:
解决:
二、部署麻烦:
解决:
三、水平扩展性差:
解决:
四、稳定性差:
解决:
1.3 横向纵向拆分
1.4 创建项目:
创建父子类项目分析:
maven-…-webapp项目 controller控制层代码 进行请求访问 故web项目!
maven-…-quickstart项目 service业务层代码mapper持久层代码都是java代码 quickstart项目即可满足!
创建父项目:
创建子项目webapp:
创建子级项目quickstart:
同理,创建子级maven-…-quickstart项目haha-common:
父类子类项目之间的联系< modules >< parent >:
如下所示:
与haha-system同理:
< build > < dependencies >< properties >< groupid >
build 编译插件
dependencies jar包依赖
properties 属性
lombok、hutool等jar包以及??jar包如何使用
2.2 boot依赖和starter的理解
java javac
2.4 springboot启动流程:
注意:Bug->Spring Boot项目中pom.xml文件带横杠解决方案
参考: Spring Boot项目中pom.xml文件带横杠解决方案
https://blog.csdn.net/qq_43102730/article/details/125337577
解决办法:打开File–>Settings–>Maven–>Ignored Files;将“√”去掉,刷新maven即可!
运行App:
阶段KTLX:
框架:
代码:
springboot1008_ktlx:
总pom.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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>springboot1008_ktlx</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>haha-admin</module>
<module>haha-system</module>
<module>haha-common</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4</version>
</parent>
<properties>
<lombok.version>1.18.22</lombok.version>
<mybatis.version>2.2.2</mybatis.version>
<mysql.version>5.1.47</mysql.version>
<druid.version>1.2.6</druid.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<!-- <scope>provided</scope> 不传递-->
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
haha-admin:
ee :
package com.aaa.haha.controller;
import lombok.Data;
@Data
public class ee {
}
hahaController :
package com.aaa.haha.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("haha")
public class hahaController {
@RequestMapping("hehe")
public String test() {
return "hello boot";
}
}
StudentController :
package com.aaa.haha.controller;
import com.aaa.haha.domain.AjaxResult;
import com.aaa.haha.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("student")
public class StudentController {
@Autowired
private StudentService studentService;
@RequestMapping("list")
public AjaxResult list(){
return AjaxResult.success( studentService.listAllStudent());
}
}
AjaxResult :
package com.aaa.haha.domain;
import lombok.Data;
@Data
public class AjaxResult {
private Integer code;
private String msg;
private Object data;
public AjaxResult(Integer code, String msg, Object data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public static AjaxResult success(){
return new AjaxResult(1,"成功",null);
}
public static AjaxResult success(Object data){
return new AjaxResult(1,"成功",data);
}
public static AjaxResult fail(){
return new AjaxResult(2,"失败",null);
}
public static AjaxResult fail(String msg){
return new AjaxResult(1,msg,null);
}
}
App :
package com.aaa.haha;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication //haha-common pom.xml spring-boot-starter-web
@MapperScan("com.aaa.haha.mapper") //扫包 否则将会com.aaa.haha.mapper.StudentMapper not fount
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
application.properties :
#当前项目访问路径
server.servlet.context-path=/boot
server.port=8090
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://localhost:3306/1009_springboot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
mybatis.type-aliases-package=com.aaa.haha.entity
mybatis.mapper-locations=classpath:mapper/*.xml
pom.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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springboot1008_ktlx</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>haha-admin</artifactId>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>haha-system</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
haha-common :
Student :
package com.aaa.haha.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
public class Student {
private Integer id;
private String name;
private String sex;
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date birthday;
private String province;
private Integer classId;
}
StudentMapper :
package com.aaa.haha.mapper;
import com.aaa.haha.entity.Student;
import java.util.List;
public interface StudentMapper {
List<Student> listAllStudent();
}
StudentServiceImpl :
package com.aaa.haha.service.impl;
import com.aaa.haha.entity.Student;
import com.aaa.haha.mapper.StudentMapper;
import com.aaa.haha.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
@Resource
private StudentMapper studentMapper;
@Override
public List<Student> listAllStudent() {
return studentMapper.listAllStudent();
}
}
eee :
package com.aaa.haha.service;
import lombok.Data;
@Data
public class eee {
}
pom.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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springboot1008_ktlx</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>haha-common</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
haha-system :
StudentService :
package com.aaa.haha.service;
import com.aaa.haha.entity.Student;
import java.util.List;
public interface StudentService {
List<Student> listAllStudent();
}
TestService :
package com.aaa.haha.service;
public class TestService {
public static void main(String[] args) {
System.out.println(123);
}
}
StudentServiceImpl :
package com.aaa.haha.service.impl;
import com.aaa.haha.entity.Student;
import com.aaa.haha.mapper.StudentMapper;
import com.aaa.haha.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
@Resource
private StudentMapper studentMapper;
@Override
public List<Student> listAllStudent() {
return studentMapper.listAllStudent();
}
}
eee :
package com.aaa.haha.service;
import lombok.Data;
@Data
public class eee {
}
StudentService :
package com.aaa.haha.service;
import com.aaa.haha.entity.Student;
import java.util.List;
public interface StudentService {
List<Student> listAllStudent();
}
TestService :
package com.aaa.haha.service;
public class TestService {
public static void main(String[] args) {
System.out.println(123);
}
}
StudentMapper.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.aaa.haha.mapper.StudentMapper">
<select id="listAllStudent" resultType="com.aaa.haha.entity.Student">
select id,name,sex,birthday,province,classId from student
</select>
</mapper>
pom.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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springboot1008_ktlx</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>haha-system</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>haha-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
数据库:
库:
#创建数据库
create database 1009_springboot
default character set utf8mb4 #设置字符集
default collate utf8mb4_general_ci #设置排序规则
表:
#创建学生表
create table student
(
id int primary key auto_increment,
name varchar(20) not null,
sex char(1) not null,
birthday date,
province varchar(20) default '河南',
classId int
);
select * from student;
insert into student
(name,sex,birthday,province,classId)
values
('张三','男','2002-01-01','湖北',1),
('李四','女','2003-01-05','河南',2),
('王五','男','2010-03-01','湖北',1),
('赵六','男','2009-01-08','河南',2),
('孙琪','女','2001-09-01','湖北',1);
实现效果:
传递性:
访问:
连接数据库请求:
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/118007.html