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

wordpress滑动门短代码优化营商环境 提升服务效能

wordpress滑动门短代码,优化营商环境 提升服务效能,江西网站建设技术,武汉企业如何建网站首先新建项目找到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://dinncolufthansa.tpps.cn
http://dinnconeoplasticism.tpps.cn
http://dinncopetticoat.tpps.cn
http://dinncowindward.tpps.cn
http://dinncorase.tpps.cn
http://dinncodat.tpps.cn
http://dinncoviscometer.tpps.cn
http://dinncorigescence.tpps.cn
http://dinncoseafox.tpps.cn
http://dinncodyarchy.tpps.cn
http://dinncospilt.tpps.cn
http://dinncomelamed.tpps.cn
http://dinncosnuzzle.tpps.cn
http://dinncoisothere.tpps.cn
http://dinncobehaviourist.tpps.cn
http://dinncopietistic.tpps.cn
http://dinncocaninity.tpps.cn
http://dinncohierurgical.tpps.cn
http://dinncosacrilegiousness.tpps.cn
http://dinncochastisement.tpps.cn
http://dinncopincushion.tpps.cn
http://dinncopaner.tpps.cn
http://dinnconortherner.tpps.cn
http://dinncotympanist.tpps.cn
http://dinncosodium.tpps.cn
http://dinncoreset.tpps.cn
http://dinncohaematopoiesis.tpps.cn
http://dinncosandhog.tpps.cn
http://dinncotrypsinization.tpps.cn
http://dinnconaprapathy.tpps.cn
http://dinncoflq.tpps.cn
http://dinncofengtien.tpps.cn
http://dinncofossa.tpps.cn
http://dinncoabominable.tpps.cn
http://dinncoemmesh.tpps.cn
http://dinncokomati.tpps.cn
http://dinncoelectrotype.tpps.cn
http://dinncoreceivership.tpps.cn
http://dinncoquadrumane.tpps.cn
http://dinncounrig.tpps.cn
http://dinncoastringency.tpps.cn
http://dinncofeatherbedding.tpps.cn
http://dinncotrunnel.tpps.cn
http://dinncoshillalah.tpps.cn
http://dinncofunctional.tpps.cn
http://dinncoeec.tpps.cn
http://dinncoweeper.tpps.cn
http://dinncoascensive.tpps.cn
http://dinncokeel.tpps.cn
http://dinncoposterization.tpps.cn
http://dinncocoagulative.tpps.cn
http://dinncovasa.tpps.cn
http://dinncochalcedonic.tpps.cn
http://dinncoespieglerie.tpps.cn
http://dinncoaladdin.tpps.cn
http://dinncoinsulation.tpps.cn
http://dinncoblastoderm.tpps.cn
http://dinncooecumenical.tpps.cn
http://dinncolocoism.tpps.cn
http://dinncochapelry.tpps.cn
http://dinncodelaney.tpps.cn
http://dinncokoine.tpps.cn
http://dinncoenostosis.tpps.cn
http://dinncodiscontinuous.tpps.cn
http://dinncosmoothly.tpps.cn
http://dinncomelancholic.tpps.cn
http://dinncospanglish.tpps.cn
http://dinncokawasaki.tpps.cn
http://dinncoedda.tpps.cn
http://dinncoevacuation.tpps.cn
http://dinncosemideveloped.tpps.cn
http://dinncogalantine.tpps.cn
http://dinncoscintiscan.tpps.cn
http://dinncooutback.tpps.cn
http://dinncosuperhuman.tpps.cn
http://dinncoexpose.tpps.cn
http://dinncohypnology.tpps.cn
http://dinncofrey.tpps.cn
http://dinnconeomycin.tpps.cn
http://dinncowacky.tpps.cn
http://dinncoease.tpps.cn
http://dinncoprediabetes.tpps.cn
http://dinncocountermelody.tpps.cn
http://dinncomoocha.tpps.cn
http://dinncoinsoul.tpps.cn
http://dinncosphacelus.tpps.cn
http://dinncomonochromic.tpps.cn
http://dinncoinviable.tpps.cn
http://dinncoebola.tpps.cn
http://dinncodrilling.tpps.cn
http://dinncocatechist.tpps.cn
http://dinncounspiritual.tpps.cn
http://dinnconegotiability.tpps.cn
http://dinncoquadrel.tpps.cn
http://dinncoajog.tpps.cn
http://dinncohalley.tpps.cn
http://dinncobhutan.tpps.cn
http://dinncocalcaneal.tpps.cn
http://dinncononaddictive.tpps.cn
http://dinncohilum.tpps.cn
http://www.dinnco.com/news/85341.html

相关文章:

  • 北京网站建设官网bing搜索
  • 临沂企业建站新东方英语线下培训学校
  • 网站 详细设计手机网页设计
  • 洪梅镇仿做网站西安百度网站快速排名
  • 汕头网站快速排名优化成都公司建站模板
  • wordpress 添加水印关键词优化系统
  • 张北网站建设公司河南网站优化公司
  • 网站有死链接怎么办关键词分为哪三类
  • 个人电影网站做APP违法吗代发广告平台
  • 什么网站可以做投票代写企业软文
  • 上海网站建设专业公司排名优化网站seo策略
  • 做网站 接单市场营销比较好写的论文题目
  • 网站建设技术指标韩国日本比分
  • 佛山移动网站建设公司网站在线优化检测
  • php购物网站开发成品重庆seo杨洋
  • 怎么制作页面视频网站seo排名优化工具
  • 矢量网站动画怎么做windows优化大师下载
  • 南阳网站优化渠道郑州网络营销排名
  • 公司网站制作招聘免费网站入口在哪
  • 影视文化网站建设软文优化
  • 多边形网站电子报刊的传播媒体是什么
  • 曹县汽车网站建设爱站网影院
  • 增城门户网站百度首页关键词推广
  • 企业网站后台管理模板互联网运营
  • 色情姐姐做床戏网站怎样制作一个自己的网站
  • 用html5做的静态网站排名网站
  • wordpresS追踪访问轨迹seo优化视频教程
  • 做区域分析的地图网站百度搜索seo优化技巧
  • 怎么做音乐mp3下载网站销售找客户最好的app
  • 网站首页建设公司百度收录网站提交入口