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

自做网站视频免费网站seo

自做网站视频,免费网站seo,电脑系统,一个人开公司怎么注册首先新建项目找到Spring Initializr 我使用的URL是https://start.spring.io这里最低的JDK版本是17,而且当网速不好的时候可能会显示超时,这里可以选用阿里云的镜像https://start.aliyun.com可以更快一些但是里面还是有一些区别的 我们这里选择Java语言&a…

首先新建项目找到Spring Initializr 我使用的URL是https://start.spring.io这里最低的JDK版本是17,而且当网速不好的时候可能会显示超时,这里可以选用阿里云的镜像https://start.aliyun.com可以更快一些但是里面还是有一些区别的

我们这里选择Java语言,Maven框架

在这里我们选择一些我们需要用到的

这个版本可以选低一点更加稳定

进来之后我们需要先等pom文件加载,我们可以选择刷新Maven

加载完之后由于我们加载了MySQL所以还不能运行可以先注释掉,然后刷新maven

后面就可以运行了,但是它默认的是8080端口,有可能会有被占用的我们可以更改端口

后面既可以运行了

运行结果就是这样的后面没有了,刚开始由于我学习的时候和别人运行的不一样,还以为是卡住了,调试了好久好久,结果发现这就已经是运行了

下面我们就可以去页面看看结果了

用阿里云镜像的输出会有点不一样但是没有问题。

下面我们就可以创建一个测试类

新建一个TestController

@RestController
public class TestController {@GetMapping("/hello")public String hello(){return "hello word!";}
}

再去页面观察

rest api规范

路径

路径又称"终点"(endpoint),表示API的具体网址。在RESTfuI架构中,每个网址代表一种资源(resource),所以网址中不能有动词,只能有名词,而且所用的名词往往与数据库的表格名对应。

Http 动词

GET(SELECT):从服务器取出资源(一项或多项)。

POST(CREATE):在服务器新建一个资源。

PUT(UPDATE):在服务器更新资源(客户端提供改变后的完整资源)。。PATCH(UPDATE):在服务器更新资源(客户端提供改变的属性)

DELETE(DELETE):从服务器删除资源。

新建一个数据库,创建表student

使用mysql语句是这样的

创建

在这里我遇到的问题是JpaRepository我继承不了,然后不断的查找问题是更改pom文件里面的内容

加入

org.springframework.data

spring-data-jpa

然后刷新一下maven就好了

创建Student

Student

package com.example.mysqldemo3.dao;import jakarta.persistence.*;import static jakarta.persistence.GenerationType.IDENTITY;@Entity
@Table(name = "student")
public class Student {@Id@Column(name = "id")@GeneratedValue(strategy = IDENTITY)private long id;@Column(name = "name")private String name;@Column(name = "email")private String email;@Column(name = "age")private int age;public long getId() {return id;}public void setId(long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getEmail() {return email;}public void setEmail(String email) {this.email = email;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}
}

返回到接口补全代码

package com.example.mysqldemo3.dao;import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;@Repository
public interface StudentRepository extends JpaRepository<Student,Long> {}

Service层

StudentService

package com.example.mysqldemo3.service;import com.example.mysqldemo3.dao.Student;public interface StudentService {Student getStudentById(long id);}

StudentServiceImpl

package com.example.mysqldemo3.service;import com.example.mysqldemo3.dao.Student;
import com.example.mysqldemo3.dao.StudentRepository;
import jakarta.persistence.Id;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class StudentServiceImpl implements StudentService{@Autowiredprivate StudentRepository StudentRepository;@Overridepublic Student getStudentById(long id) {return StudentRepository.findById(id).orElseThrow(RuntimeException::new) ;}
}

controller层

package com.example.mysqldemo3.controller;import com.example.mysqldemo3.dao.Student;
import com.example.mysqldemo3.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;@RestController
public class StudentController {@Autowiredprivate StudentService studentService;@GetMapping("/student/{id}")public Student getStudentById(@PathVariable long id){return studentService.getStudentById(id);}
}

连接数据库这些配置写在application里面

数据库

spring.application.name=mysql-demo3
server.port=8085
spring.datasource.url=jdbc:mysql://localhost:3306/数据库名字?characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=sgz250hhh

在数据库中填入数据

后面就可以去网页测试了

再往后我们需要做一些信息的隐藏,不想去展示这莫多的数据

创建

StudentDTO进行封装

package com.example.mysqldemo3.dto;public class StudentDTO {private long id;private String name;private String email;public long getId() {return id;}public void setId(long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getEmail() {return email;}public void setEmail(String email) {this.email = email;}
}

新建converter将student的数据进行转换成DTO

StudentConverter

package com.example.mysqldemo3.converter;import com.example.mysqldemo3.dao.Student;
import com.example.mysqldemo3.dto.StudentDTO;public class StudentConverter {public static StudentDTO converStudent(Student student){//student转换成DTO对象StudentDTO studentDTO = new StudentDTO();studentDTO.setId(student.getId());studentDTO.setName(student.getName());studentDTO.setEmail(student.getEmail());return studentDTO;}
}

新建

判断是否查询成功

Response

package com.example.mysqldemo3;public class Response <T>{//返回后端的一些格式private T data;private boolean success;private String errorMsg;public static <K> Response<K> newSuccess(K data){//返回成功Response<K> response = new Response<>();response.setData(data);response.setSuccess(true);return response;}public static  Response<Void> newFail(String errorMsg){//返回失败Response<Void> response = new Response<>();response.setErrorMsg(errorMsg);response.setSuccess(false);return response;}public T getData() {return data;}public void setData(T data) {this.data = data;}public boolean isSuccess() {return success;}public void setSuccess(boolean success) {this.success = success;}public String getErrorMsg() {return errorMsg;}public void setErrorMsg(String errorMsg) {this.errorMsg = errorMsg;}
}

StudentService

package com.example.mysqldemo3.service;import com.example.mysqldemo3.dao.Student;
import com.example.mysqldemo3.dto.StudentDTO;public interface StudentService {StudentDTO getStudentById(long id);}

StudentServiceImpl

package com.example.mysqldemo3.service;import com.example.mysqldemo3.converter.StudentConverter;
import com.example.mysqldemo3.dao.Student;
import com.example.mysqldemo3.dao.StudentRepository;
import com.example.mysqldemo3.dto.StudentDTO;
import jakarta.persistence.Id;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class StudentServiceImpl implements StudentService{@Autowiredprivate StudentRepository StudentRepository;@Overridepublic StudentDTO getStudentById(long id) {Student student = StudentRepository.findById(id).orElseThrow(RuntimeException::new);return StudentConverter.converStudent(student);}
}

StudentController

package com.example.mysqldemo3.controller;import com.example.mysqldemo3.Response;
import com.example.mysqldemo3.dao.Student;
import com.example.mysqldemo3.dto.StudentDTO;
import com.example.mysqldemo3.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;@RestController
public class StudentController {@Autowiredprivate StudentService studentService;@GetMapping("/student/{id}")public Response<StudentDTO> getStudentById(@PathVariable long id){return Response.newSuccess(studentService.getStudentById(id));}
}

刷新页面

就可以看见age被隐藏起来了

后面的就是增加删除和修改的操作可以使用Postman进行接口测试,可以直接官网下载

StudentServiceImpl

package com.example.mysqldemo3.service;import com.example.mysqldemo3.converter.StudentConverter;
import com.example.mysqldemo3.dao.Student;
import com.example.mysqldemo3.dao.StudentRepository;
import com.example.mysqldemo3.dto.StudentDTO;
import jakarta.persistence.Id;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;import java.util.List;@Service
public class StudentServiceImpl implements StudentService{@Autowiredprivate StudentRepository StudentRepository;@Overridepublic StudentDTO getStudentById(long id) {Student student = StudentRepository.findById(id).orElseThrow(RuntimeException::new);return StudentConverter.converStudent(student);}@Overridepublic Long addNewStudent(StudentDTO studentDTO) {List<Student> studentList = StudentRepository.findByEmail(studentDTO.getEmail());if (!CollectionUtils.isEmpty(studentList)){throw new IllegalStateException("email:"+studentDTO.getEmail()+"has been taken");}Student student = StudentRepository.save(StudentConverter.converStudent(studentDTO));return student.getId();}@Overridepublic void deleteStudentById(long id) {StudentRepository.findById(id).orElseThrow(()->new IllegalArgumentException("id"+id+"doesn`s exist!"));StudentRepository.deleteById(id);}@Overridepublic StudentDTO updateStudentById(long id, String name, String email) {Student studentDB = StudentRepository.findById(id).orElseThrow(()->new IllegalArgumentException("id"+id+"doesn`s exist!"));if (StringUtils.hasLength(name) && !studentDB.getName().equals(name)){studentDB.setName(name);}if(StringUtils.hasLength(email) && !studentDB.getEmail().equals(email)){studentDB.setEmail(email);}Student student = StudentRepository.save(studentDB);return StudentConverter.converStudent(student);}}

StudentService

package com.example.mysqldemo3.service;import com.example.mysqldemo3.dao.Student;
import com.example.mysqldemo3.dto.StudentDTO;public interface StudentService {StudentDTO getStudentById(long id);Long addNewStudent(StudentDTO studentDTO);void deleteStudentById(long id);StudentDTO updateStudentById(long id, String name, String email);
}

StudentRepository

package com.example.mysqldemo3.dao;import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;import java.util.List;@Repository
public interface StudentRepository extends JpaRepository<Student,Long> {List<Student> findByEmail(String emile);}

StudentConverter

package com.example.mysqldemo3.converter;import com.example.mysqldemo3.dao.Student;
import com.example.mysqldemo3.dto.StudentDTO;public class StudentConverter {public static StudentDTO converStudent(Student student){//student转换成DTO对象StudentDTO studentDTO = new StudentDTO();studentDTO.setId(student.getId());studentDTO.setName(student.getName());studentDTO.setEmail(student.getEmail());return studentDTO;}public static Student converStudent(StudentDTO StudentDTO){//student转换成DTO对象Student student = new Student();student.setName(StudentDTO.getName());student.setEmail(StudentDTO.getEmail());return student;}
}

StudentController

package com.example.mysqldemo3.controller;import com.example.mysqldemo3.Response;
import com.example.mysqldemo3.dao.Student;
import com.example.mysqldemo3.dto.StudentDTO;
import com.example.mysqldemo3.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController
public class StudentController {@Autowiredprivate StudentService studentService;@GetMapping("/student/{id}")public Response<StudentDTO> getStudentById(@PathVariable long id){return Response.newSuccess(studentService.getStudentById(id));}@PostMapping("/student")public Response<Long> addNewStudent(@RequestBody StudentDTO studentDTO){return Response.newSuccess(studentService.addNewStudent(studentDTO));}@DeleteMapping("/student/{id}")public void deleteStudentById(@PathVariable long id){studentService.deleteStudentById(id);}@PutMapping("/student/{id}")public Response<StudentDTO> updateStudentById(@PathVariable long id,@RequestParam(required = false) String name,@RequestParam(required = false) String email){return Response.newSuccess(studentService.updateStudentById(id,name,email));}
}

最后就可以使用maven对文件进行打包了


文章转载自:
http://ficelle.jnpq.cn
http://choana.jnpq.cn
http://reporting.jnpq.cn
http://disinterest.jnpq.cn
http://mode.jnpq.cn
http://rallentando.jnpq.cn
http://dulcification.jnpq.cn
http://amblygonite.jnpq.cn
http://reinforcer.jnpq.cn
http://trechometer.jnpq.cn
http://flutter.jnpq.cn
http://torah.jnpq.cn
http://glacon.jnpq.cn
http://bibliothetic.jnpq.cn
http://middlebreaker.jnpq.cn
http://indissolubility.jnpq.cn
http://curitiba.jnpq.cn
http://recognizability.jnpq.cn
http://scry.jnpq.cn
http://psephomancy.jnpq.cn
http://lecithoid.jnpq.cn
http://radioamplifier.jnpq.cn
http://cyetic.jnpq.cn
http://ounce.jnpq.cn
http://yellowback.jnpq.cn
http://anhemitonic.jnpq.cn
http://costard.jnpq.cn
http://spiritualistic.jnpq.cn
http://hematemesis.jnpq.cn
http://scoreboard.jnpq.cn
http://rachides.jnpq.cn
http://unsaturate.jnpq.cn
http://balancer.jnpq.cn
http://majority.jnpq.cn
http://colporteur.jnpq.cn
http://kismet.jnpq.cn
http://juneberry.jnpq.cn
http://compounder.jnpq.cn
http://prelithic.jnpq.cn
http://dentinasal.jnpq.cn
http://thiobacillus.jnpq.cn
http://clothing.jnpq.cn
http://matrilinear.jnpq.cn
http://kolkhoznik.jnpq.cn
http://thyiad.jnpq.cn
http://sistroid.jnpq.cn
http://alternative.jnpq.cn
http://metalanguage.jnpq.cn
http://eumycete.jnpq.cn
http://helaine.jnpq.cn
http://vicennial.jnpq.cn
http://okie.jnpq.cn
http://polysome.jnpq.cn
http://nickeline.jnpq.cn
http://statewide.jnpq.cn
http://damnification.jnpq.cn
http://junius.jnpq.cn
http://fluently.jnpq.cn
http://ulexite.jnpq.cn
http://indescribable.jnpq.cn
http://mellow.jnpq.cn
http://pastiness.jnpq.cn
http://achromatize.jnpq.cn
http://tolerate.jnpq.cn
http://bedight.jnpq.cn
http://seemliness.jnpq.cn
http://alveolate.jnpq.cn
http://tripoli.jnpq.cn
http://portrayer.jnpq.cn
http://prosaically.jnpq.cn
http://sati.jnpq.cn
http://fructicative.jnpq.cn
http://nonsoap.jnpq.cn
http://nitroglycerine.jnpq.cn
http://centerpiece.jnpq.cn
http://knock.jnpq.cn
http://enzootic.jnpq.cn
http://overelaborate.jnpq.cn
http://inclemency.jnpq.cn
http://clonesome.jnpq.cn
http://customs.jnpq.cn
http://jointed.jnpq.cn
http://varec.jnpq.cn
http://unrope.jnpq.cn
http://zambomba.jnpq.cn
http://recuperative.jnpq.cn
http://suckling.jnpq.cn
http://unbent.jnpq.cn
http://yellowy.jnpq.cn
http://rfc.jnpq.cn
http://skylounge.jnpq.cn
http://suctorial.jnpq.cn
http://einkanter.jnpq.cn
http://physiology.jnpq.cn
http://hyperpituitarism.jnpq.cn
http://geopolitic.jnpq.cn
http://sopped.jnpq.cn
http://darhan.jnpq.cn
http://integrate.jnpq.cn
http://cosmo.jnpq.cn
http://www.hrbkazy.com/news/71254.html

相关文章:

  • 深圳建设网站公司排名关于新品牌的营销策划
  • 什么软件能把做的网站上传站长工具seo综合查询关键词
  • 网站制作1今天刚刚发生的重大新闻
  • 信息门户网站是什么怎么给客户推广自己的产品
  • 凡科做的手机网站可以导出来邀请注册推广赚钱的app
  • wordpress源码买卖seo资讯推推蛙
  • 地方性门户网站有哪些如何分析百度指数
  • ui培训多少学费天津seo招聘
  • 化妆品企业网站建设中国四大软件外包公司
  • 做五金出口在哪个网站好点合肥seo推广外包
  • 湖北聚四方建设有限公司网站seo站内优化站外优化
  • 成都高端网页设计公司百度网站优化工具
  • 为赌博网站做代理网店买卖有哪些平台
  • 开发公司给物业公司开办费百度seo排名优化
  • wordpress后台500错误以下属于网站seo的内容是
  • 咨询公司有哪些seo投放是什么意思
  • 帮忙做快站旅游网站国外网站如何搭建网页
  • 网站怎么做舆情监测拉新推广
  • 网站建设中 英文360营销推广
  • app软件推广文案的范文seo 工具推荐
  • 建工网校官网登录入口优化关键词方法
  • 网站建设要会哪些方面搜索引擎排名谷歌
  • 西安营销型网站建设动力无限网站外链出售
  • 宁波个人网站建设aso具体优化
  • 网站维护包括的内容营销策划书模板范文
  • 毕业论文做ppt模板下载网站汽车行业网站建设
  • 学网站建设要什么百度推广一个月多少钱
  • 什么网站能通过做任务赚钱搜索引擎有哪几个网站
  • 湖北建设局网站首页google chrome官网入口
  • 福州建设局网站百度打广告多少钱一个月