diff --git a/111/pom.xml b/111/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..d51c88a048e3e9b90c4e73354ada4617e25fc9c9 --- /dev/null +++ b/111/pom.xml @@ -0,0 +1,37 @@ + + + + swpu-spring-projects + com.swpu + 0.0.1-SNAPSHOT + + 4.0.0 + + 111 + + + 11 + 11 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.5.2 + + + + org.projectlombok + lombok + + + + + + + \ No newline at end of file diff --git a/12/pom.xml b/12/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..21fd0e4256c40e3424fa201b65e6ceaba94b0185 --- /dev/null +++ b/12/pom.xml @@ -0,0 +1,44 @@ + + + + swpu-spring-projects + com.swpu + 0.0.1-SNAPSHOT + + 4.0.0 + + 12 + + + org.mybatis + mybatis + 3.5.7 + + + + + 11 + 11 + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.5.2 + + + + org.projectlombok + lombok + + + + + + + + \ No newline at end of file diff --git a/12/src/main/java/com/swpu/PersonApplication.java b/12/src/main/java/com/swpu/PersonApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..a3adf7c3bbbae16befcbc133cc5aea003f7ea233 --- /dev/null +++ b/12/src/main/java/com/swpu/PersonApplication.java @@ -0,0 +1,18 @@ +package com.swpu; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@MapperScan({"com.swpu.dao.**"}) +@SpringBootApplication + +public class PersonApplication { + public static void main(String[] args) { + SpringApplication.run(PersonApplication.class,args); + } + + + + +} diff --git a/12/src/main/java/com/swpu/controller/PersonController.java b/12/src/main/java/com/swpu/controller/PersonController.java new file mode 100644 index 0000000000000000000000000000000000000000..01a37065d89c3a38df01f1fc8919d7e9cc72f572 --- /dev/null +++ b/12/src/main/java/com/swpu/controller/PersonController.java @@ -0,0 +1,49 @@ +package com.swpu.controller; + + +import com.swpu.dao.PersonDao; +import com.swpu.entity.PersonEntity; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +@RestController +@RequestMapping(value="/libuliyan") +public class PersonController { + + @Resource + private PersonDao personDao; + + @GetMapping(value="/findAll") + public Object findAll(){ + List list= personDao.findAll(); + return list; + } + @GetMapping(value="/findbyId") + public Object findbyId(@RequestParam(value ="id") int id){ + return personDao.FindId(id); + } + + @PostMapping(value="/insert") + public Object insert(@RequestBody PersonEntity entity){ + + personDao.insert(entity); + return "插入成功"; + } + + @PutMapping(value = "/update") + public Object update(@RequestBody PersonEntity entity){ + + personDao.update(entity); + return "更新成功"; + } + + @DeleteMapping(value="/delete") + public Object delete(@RequestParam(value = "id") int id){ + personDao.delete(id); + return "删除成功"; + } + + +} diff --git a/12/src/main/java/com/swpu/controller/SwpuAuthController.java b/12/src/main/java/com/swpu/controller/SwpuAuthController.java new file mode 100644 index 0000000000000000000000000000000000000000..fc59ddb4e7e69884599da4fd6dba63ebe17b453e --- /dev/null +++ b/12/src/main/java/com/swpu/controller/SwpuAuthController.java @@ -0,0 +1,147 @@ +package com.swpu.controller; + +import com.swpu.dao.SwpuAuthDao; +import com.swpu.entity.SwpuAuthEntity; +import com.swpu.util.Result; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; +import java.util.UUID; + +@RestController +@RequestMapping(value = "/libuli") + + +public class SwpuAuthController { + + @Resource + private SwpuAuthDao swpuAuthDao; + + + @GetMapping(value = "/findAll") + public Result findAll(){ + + Result result = new Result(); + List list =null; + try { + list = swpuAuthDao.findAll(); + } catch (Exception e) { + result.setStatus(false); + result.setData(-1); + result.setMessage(e.getMessage()); + } + if(list!=null){ + result.setStatus(true); + result.setData(list); + result.setMessage("查找相符"); + } + else{ + result.setStatus(false); + result.setData(-1); + result.setMessage("没有相符的"); + } + + return result; + } + + + @GetMapping(value = "/login") + public Result findByUserAndPassword(@RequestParam ("username") String userName, @RequestParam("password") String password){ + + Result result = new Result(); + SwpuAuthEntity X = swpuAuthDao.findByUserAndPassword(userName, password); + if(X!=null){ + result.setStatus(true); + result.setData(X); + result.setMessage("查找相符"); + } + else{ + result.setStatus(false); + result.setData(-1); + result.setMessage("没有相符的"); + } + return result; + } + + @PostMapping(value = "/register") + public Result insert(@RequestBody SwpuAuthEntity entity){ + + Result result = new Result(); + String id = UUID.randomUUID().toString().replace("_",""); + entity.setId(id); + + int flag = 0; + try { + flag = swpuAuthDao.insert(entity); + + } + + catch (Exception e) { + result.setStatus(false); + result.setData(-1); + result.setMessage(e.getMessage()); + } + if(flag >0){ + result.setStatus(true); + result.setData(1); + result.setMessage("已插入"); + } + else{ + result.setStatus(false); + result.setData(-1); + result.setMessage("插入失败"); } + + + + + + return result; + + } + + @PutMapping(value = "/update") + public Result update(@RequestBody SwpuAuthEntity entity){ + + Result result = new Result(); + int flag = 0; + try { + flag = swpuAuthDao.update(entity); + } catch (Exception e) { + result.setStatus(false); + result.setData(-1); + result.setMessage(e.getMessage()); + } + if(flag >0){ + result.setStatus(true); + result.setData(1); + result.setMessage("已更新"); + } + else{ + result.setStatus(false); + result.setData(-1); + result.setMessage("更新失败"); + + } + return result; + } + + @DeleteMapping(value = "/delete") + public Result delete(@RequestParam("id") String id){ + + Result result = new Result(); + int flag = swpuAuthDao.delete(id); + if(flag >0){ + result.setStatus(true); + result.setData(1); + result.setMessage("已删除"); + } + else{ + result.setStatus(false); + result.setData(-1); + result.setMessage("删除失败"); + } + return result; + } + +} diff --git a/12/src/main/java/com/swpu/dao/PersonDao.java b/12/src/main/java/com/swpu/dao/PersonDao.java new file mode 100644 index 0000000000000000000000000000000000000000..4085d13fb7e49bde38cbf99b5dca4526c896c240 --- /dev/null +++ b/12/src/main/java/com/swpu/dao/PersonDao.java @@ -0,0 +1,14 @@ +package com.swpu.dao; + +import com.swpu.entity.PersonEntity; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface PersonDao { + PersonEntity FindId(@Param(value="id") int Id); + List findAll(); + int insert(PersonEntity entity); + int update(PersonEntity entity); + int delete(@Param(value="Id") int Id); +} diff --git a/12/src/main/java/com/swpu/dao/SwpuAuthDao.java b/12/src/main/java/com/swpu/dao/SwpuAuthDao.java new file mode 100644 index 0000000000000000000000000000000000000000..346b122e163e2296b1427906812e24e126f6891d --- /dev/null +++ b/12/src/main/java/com/swpu/dao/SwpuAuthDao.java @@ -0,0 +1,54 @@ +package com.swpu.dao; + +import com.swpu.entity.SwpuAuthEntity; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @author wales + *

+ * 第一阶段 - DAO + */ +public interface SwpuAuthDao { + + /** + * 查询所有 + * + * @return {@link SwpuAuthEntity} + */ + List findAll(); + + /** + * 根据 用户名 和 密码 查询数据库数据 + * + * @param username 用户名 + * @param password 密码 + * @return {@link SwpuAuthEntity} + */ + SwpuAuthEntity findByUserAndPassword(@Param("userName") String username, @Param("password") String password); + + /** + * 增加操作 + * + * @param entity {@link SwpuAuthEntity} + * @return {@link Integer} + */ + int insert(SwpuAuthEntity entity); + + /** + * 修改操作 + * + * @param entity {@link SwpuAuthEntity} + * @return {@link Integer} + */ + int update(SwpuAuthEntity entity); + + /** + * 删除操作 + * + * @param id id + * @return {@link Integer} + */ + int delete(@Param("id") String id); +} diff --git a/12/src/main/java/com/swpu/entity/PersonEntity.java b/12/src/main/java/com/swpu/entity/PersonEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..107d528bce6b42771dc8a969ba9ed17d8df181d9 --- /dev/null +++ b/12/src/main/java/com/swpu/entity/PersonEntity.java @@ -0,0 +1,16 @@ +package com.swpu.entity; + + +import lombok.Data; + +@Data +public class PersonEntity { + private int Id; + private String Name; + private String School; + private int RoomNumber; + private int Grade; + + + +} diff --git a/12/src/main/java/com/swpu/entity/SwpuAuthEntity.java b/12/src/main/java/com/swpu/entity/SwpuAuthEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..a85eb79a231799819395da1a28fbcb08b076e8f9 --- /dev/null +++ b/12/src/main/java/com/swpu/entity/SwpuAuthEntity.java @@ -0,0 +1,32 @@ +package com.swpu.entity; + +import lombok.Data; + +/** + * @author wales + *

+ * 用户信息验证表 + */ +@Data +public class SwpuAuthEntity { + + /** + * ID + */ + private String id; + + /** + * 用户名 + */ + private String userName; + + /** + * 密码 + */ + private String password; + + /** + * 学校 + */ + private String school; +} diff --git a/12/src/main/java/com/swpu/util/Result.java b/12/src/main/java/com/swpu/util/Result.java new file mode 100644 index 0000000000000000000000000000000000000000..bdcb1db30119e0bbd6e3cc560aa3697f9fb35fef --- /dev/null +++ b/12/src/main/java/com/swpu/util/Result.java @@ -0,0 +1,26 @@ +package com.swpu.util; + +import lombok.Data; + +/** + * @author wales + *

+ * 自定义的返回值 + *

+ * 目的是为了告诉前端当前的数据是否正确,并作出相应的处理 + * + *

    + *
  • 1. 如果后台当前数据是正确的,那么 status 赋值为 true、反之为 false
  • + *
  • 2. 如果 status 为 true,那么就需要将返回的数据赋值给 data,所有正确的数据都存放在 data 中,一并返回给前端
  • + *
  • 3. 如果 status 为 false,那么 data 中则不需要存任何数据,可以象征性的给 data 赋值为 -1,只要需要给 message 赋值,告诉前端错误的内容、理由
  • + *
+ */ +@Data +public class Result { + + private boolean status; + + private Object data; + + private String message; +} diff --git a/12/src/main/resources/application.yml b/12/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..f6702d1d53fc6ae82a9c5597b39aa797c0a16468 --- /dev/null +++ b/12/src/main/resources/application.yml @@ -0,0 +1,23 @@ +spring: + application: + name: swpu-spring-projects + # 数据库连接信息 + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://192.168.126.129:20000/swpu_db + username: swpu_user + password: '2121709a*' + # 数据库连接池 + type: com.zaxxer.hikari.HikariDataSource + hikari: + maximum-pool-size: 10000 +# 项目端口 +server: + port: 20000 + +# MyBatis XML 配置 +mybatis: + mapper-locations: classpath:mapper/**.xml + # 开启 驼峰支持 + configuration: + map-underscore-to-camel-case: true diff --git a/12/src/main/resources/mapper/Personmapper.xml b/12/src/main/resources/mapper/Personmapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..16218ae2eec9b07bf784be316c947d6d71e8c5bd --- /dev/null +++ b/12/src/main/resources/mapper/Personmapper.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + insert into person (id, name, school, roomNumber, grade) + values (#{Id, javaType = Integer}, #{Name,javaType =String}, + #{School, javaType = String},#{RoomNumber,javaType=Integer},#{Grade,javaType=Integer}) + + + + update person + set + name = #{Name,javaType =String}, + school = #{School, javaType = String}, + roomNumber = #{RoomNumber,javaType=Integer}, + grade = #{Grade,javaType=Integer} + where id=#{Id, javaType = Integer} + + + + delete + from person su + where 1 = 1 + and su.id = #{id, javaType = Integer} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/12/src/main/resources/mapper/SwpuAuthMapper.xml b/12/src/main/resources/mapper/SwpuAuthMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..aeabd6edc3f8ae4bb9147baff1522597a3312fed --- /dev/null +++ b/12/src/main/resources/mapper/SwpuAuthMapper.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + id, username, password, school + + + + + + + + + + + insert into swpu_auths (id, username, password, school) + values (#{id, javaType = String}, #{userName, javaType = String}, + #{password, javaType = String}, #{school, javaType = String}) + + + + + update swpu_auths + set username = #{userName, javaType = String}, + password = #{password, javaType = String}, + school = #{school, javaType = String} + where id = #{id, javaType = String} + + + + + delete + from swpu_auths sa + where 1 = 1 + and sa.id = #{id, javaType = String} + + diff --git a/pom.xml b/pom.xml index d545cc00c459e2e302c74a07b7f53ea22551e512..53ccef4d65f83ae7d0d23d8652e454dc4947d87c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,9 @@ pom swpu-spring-projects-boot - swpu-spring-projects-testify + swpu-springboot-liyan-projects + 111 + 12 org.springframework.boot @@ -77,6 +79,24 @@ spring-boot-starter-test test - + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + diff --git a/sql/swpu_info.sql b/sql/swpu_info.sql index 0b54a2d94e873530fe135c70a7ea74f8d90be715..05dbd15161991a20d007570b33d86d5824e3a9a8 100644 --- a/sql/swpu_info.sql +++ b/sql/swpu_info.sql @@ -1,12 +1,12 @@ -create table swpu_info -( - id varchar(100) not null comment '主键ID' - primary key, - p_id int not null comment '联合ID', - contract_term double null comment '合同期限', - conversion_time date null comment '转正日期', - notWork_date date null comment '离职日期', - begin_contract date null comment '合同起始日期', - end_contract date null comment '合同终止日期', - work_age int null comment '工龄' -) charset = utf8; +# create table swpu_info +# ( +# id varchar(100) not null comment '主键ID' +# primary key, +# p_id int not null comment '联合ID', +# contract_term double null comment '合同期限', +# conversion_time date null comment '转正日期', +# notWork_date date null comment '离职日期', +# begin_contract date null comment '合同起始日期', +# end_contract date null comment '合同终止日期', +# work_age int null comment '工龄' +# ) charset = utf8; diff --git a/sql/swpu_user.sql b/sql/swpu_user.sql index 0970965b847c3b243894eec5db1aba249ad3483b..8c0f67d44706274b2522a0fbbac44fe7701ce610 100644 --- a/sql/swpu_user.sql +++ b/sql/swpu_user.sql @@ -1,13 +1,13 @@ -create table swpu_user -( - id varchar(100) not null comment '主键ID' - primary key, - department_id int null comment '所属部门', - job_level_id int null comment '职称ID', - posId int null comment '职位ID', - engage_form varchar(8) null comment '聘用形式', - specialty varchar(32) null comment '所属专业', - school varchar(32) null comment '毕业院校', - begin_date date null comment '入职日期', - work_id char(8) null comment '工号' -) charset = utf8; +# create table swpu_userliyan +# ( +# id varchar(100) not null comment '主键ID' +# primary key, +# department_id int null comment '所属部门', +# job_level_id int null comment '职称ID', +# posId int null comment '职位ID', +# engage_form varchar(8) null comment '聘用形式', +# specialty varchar(32) null comment '所属专业', +# school varchar(32) null comment '毕业院校', +# begin_date date null comment '入职日期', +# work_id char(8) null comment '工号' +# ) charset = utf8; diff --git a/src/main/java/com/swpu/liyan/JavaSpringBootController.java b/src/main/java/com/swpu/liyan/JavaSpringBootController.java new file mode 100644 index 0000000000000000000000000000000000000000..3e9260494358d706371e5fb8376b5e6bead27718 --- /dev/null +++ b/src/main/java/com/swpu/liyan/JavaSpringBootController.java @@ -0,0 +1,66 @@ +package com.swpu.liyan; + +import org.springframework.web.bind.annotation.*; + +/** + * @author wales + *

+ * Spring Boot Controller 接口开发基础 + * + *

    + *
  • 1. @ 开头的英文单词 叫 注解,其作用是约束代码的作用域
  • + *
  • 2. @RestController 注解 代表当前类中的方法中的数据可以跨本机、跨服务器、跨项目访问
  • + *
  • 3. @RequestMapping 注解 代表着设置网址/接口地址/请求地址 其本质就是设置一个 URL
  • + *
+ */ +@RestController +@RequestMapping(value = "/login") +public class JavaSpringBootController { + + /** + * GetMapping - 代表着当前的方法只能通过 GET 请求来访问 http://localhost:8080/login/find + * + * @return object + */ + @GetMapping(value = "/find") + public Object add(@RequestParam(value = "a") int a, @RequestParam(value = "c") int c, + @RequestParam(value = "z") int z) { + var y = (c + a) * z; + return "计算结果为: " + y; + } + public Object set(@RequestParam(value="s") String s) { + + return "计算结果为: " + s; + } + + /** + * PostMapping - 代表着当前的方法只能通过 POST 请求来访问 http://localhost:8080/login/insert + * + * @return object + */ + @PostMapping(value = "/insert") + public Object test() { + return "This is Post !"; + } + + /** + * PutMapping - 代表着当前的方法只能通过 PUT 请求来访问 http://localhost:8080/login/update + * + * @return object + */ + @PutMapping(value = "/update") + public Object update() { + return "Want Update !"; + } + + /** + * DeleteMapping - 代表着当前的方法只能通过 DELETE 请求来访问 http://localhost:8080/login/delete + * + * @return object + */ + @DeleteMapping(value = "/delete") + public Object delete() { + return "Hello Delete"; + } + +} diff --git a/swpu-spring-projects-boot/src/main/java/com/swpu/SwpuSpringProjectsApplication.java b/swpu-spring-projects-boot/src/main/java/com/swpu/PersonApplication.java similarity index 87% rename from swpu-spring-projects-boot/src/main/java/com/swpu/SwpuSpringProjectsApplication.java rename to swpu-spring-projects-boot/src/main/java/com/swpu/PersonApplication.java index c53fcd7e7c9b12f9384e2384c4ada4c6a4efead6..a61dd78ed531995d03df0f15e5547884c9fc1934 100644 --- a/swpu-spring-projects-boot/src/main/java/com/swpu/SwpuSpringProjectsApplication.java +++ b/swpu-spring-projects-boot/src/main/java/com/swpu/PersonApplication.java @@ -17,14 +17,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; */ @MapperScan({"com.swpu.dao.**"}) @SpringBootApplication -public class SwpuSpringProjectsApplication { +public class PersonApplication { /** * 主函数 仅仅只比我们的 Java-Base-Projects 项目多了一个 Spring 自己的 方法调用 * @param args args */ public static void main(String[] args) { - SpringApplication.run(SwpuSpringProjectsApplication.class, args); + SpringApplication.run(PersonApplication.class, args); } } diff --git a/swpu-spring-projects-boot/src/main/java/com/swpu/entity/PersonEntity.java b/swpu-spring-projects-boot/src/main/java/com/swpu/entity/PersonEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..a373914d77f8b57c1f041160a33d9ac01840f849 --- /dev/null +++ b/swpu-spring-projects-boot/src/main/java/com/swpu/entity/PersonEntity.java @@ -0,0 +1,5 @@ +package com.swpu.entity; + +public class PersonEntity { + +} diff --git a/swpu-spring-projects-boot/src/main/resources/application.yml b/swpu-spring-projects-boot/src/main/resources/application.yml index 2a647f79c18ef95c646f1c31968c923c3d2ab3c2..607441598b2a9d6f9589118093b8d59c74e778de 100644 --- a/swpu-spring-projects-boot/src/main/resources/application.yml +++ b/swpu-spring-projects-boot/src/main/resources/application.yml @@ -1,35 +1,10 @@ spring: application: name: swpu-spring-projects - # 数据库连接信息 - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/swpu_db - username: swpu_user - password: '123456789' - # 数据库连接池 - type: com.zaxxer.hikari.HikariDataSource - hikari: - minimum-idle: 5 - # 空闲连接存活最大时间,默认600000(10分钟) - idle-timeout: 180000 - # 连接池最大连接数,默认是10 - maximum-pool-size: 10 - # 此属性控制从池返回的连接的默认自动提交行为,默认值:true - auto-commit: true - # 连接池名称 - pool-name: SWPU-DB - # 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟 - max-lifetime: 1800000 - # 数据库连接超时时间,默认30秒,即30000 - connection-timeout: 30000 -# 项目端口 + + + + + server: port: 20000 - -# MyBatis XML 配置 -mybatis: - mapper-locations: classpath:mapper/**.xml - # 开启 驼峰支持 - configuration: - map-underscore-to-camel-case: true diff --git a/swpu-springboot-liyan-projects/pom.xml b/swpu-springboot-liyan-projects/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..c691c423a4594421f14ab703a0488f5e3058e4ba --- /dev/null +++ b/swpu-springboot-liyan-projects/pom.xml @@ -0,0 +1,37 @@ + + + + swpu-spring-projects + com.swpu + 0.0.1-SNAPSHOT + + 4.0.0 + + swpu-springboot-liyan-projects + + + 11 + 11 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.5.2 + + + + org.projectlombok + lombok + + + + + + + \ No newline at end of file diff --git a/swpu-springboot-liyan-projects/src/main/java/com/swpu/SwpuSpringAppAplication.java b/swpu-springboot-liyan-projects/src/main/java/com/swpu/SwpuSpringAppAplication.java new file mode 100644 index 0000000000000000000000000000000000000000..0b932015176bf882811047f7e107306283d76125 --- /dev/null +++ b/swpu-springboot-liyan-projects/src/main/java/com/swpu/SwpuSpringAppAplication.java @@ -0,0 +1,7 @@ +package com.swpu; + +public class SwpuSpringAppAplication { + public static void main(String[] args) { + + } +}