温州专业营销网站建设,wordpress 幻灯片代码在哪,贸易网站设计,沈阳人流//1.配置项目环境#xff0c;创建Spring Boot项目。 //2.数据库设置#xff0c;配置数据库。 //3.创建实体类#xff0c;映射到数据库。 //4.创建数据处理层类#xff0c;Repository //5.创建业务处理类#xff0c;Service类 //6.创建控制器类#xff0c;Controller类 Ar…//1.配置项目环境创建Spring Boot项目。 //2.数据库设置配置数据库。 //3.创建实体类映射到数据库。 //4.创建数据处理层类Repository //5.创建业务处理类Service类 //6.创建控制器类Controller类 Article.java java import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; Entity public class Article{ Id GeneratedValue(strategy GenerationType.AOTU) private Long id; private String title; private String content; private String author; //省略构造函数、getter和setter方法 //省略toString方法 //一个实体类完成了 } ArticleRepository.java数据访问层类 java import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import java.util.List; public interface ArticleRepository extends JpaRepositoryArticle,Long{ //可以在此自定义查询方法 //根据作者名查询文章 ListArticle findByAuthor(String author); //根据标题和作者查询文章 ListArticle findByTitleAndAuthor(String title,String author); //使用JPQL查询语句查询文章 Query(Select a FROM Article a WHERE a.title LIKE %:keyword% OR a.content LIKE %:keyword%) ListArticle fintByKeyword(String keyword); } ArticleService.Java(业务逻辑层) java import org.springframework.beans.factory. annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; Service public class ArticleService{ private final ArticleRepository articleRepository; Autowired public ArticleService(ArticleRepository articleRepository){ this.articleRepository articleRepository; } public ListArticlegetAllArticles(){ return articleRepository.findAll(); } public OptionalArticlegetArticleById(Long id){ return articleRepository.findByID(id); } public Article createArticle(Article article){ return articleRepository.save(article); } /** public void updateArticle(Long id, Article article) { OptionalArticle existingArticle articleRepository.findById(id); if (existingArticle.isPresent()) { Article updatedArticle existingArticle.get(); updatedArticle.setTitle(article.getTitle()); updatedArticle.setContent(article.getContent()); updatedArticle.setAuthor(article.getAuthor()); articleRepository.save(updatedArticle); } } **/ public void deleteArticle(Long id){ articleRepository.deleteById(id); } } ArticleController.java(控制器类) java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Optional; RestContrller RequestMapping(/articles) public class ArticleController{ private final ArticleService articleService; Autowired public ArticleControler( ArticleService articleService ){ tihs.articleService articleService; } GetMapping public ResponseEntityListArticlegetAllArticles(){ ListArticlearticles articleService.getAllArticles; return new ResponseEntity(articles,HttpStatus.OK) } //以下为粘贴 GetMapping(/{id}) public ResponseEntityArticle getArticleById(PathVariable Long id) { OptionalArticle article articleService.getArticleById(id); return article.map(value - new ResponseEntity(value, HttpStatus.OK)) .orElseGet(() - new ResponseEntity(HttpStatus.NOT_FOUND)); } PostMapping public ResponseEntityArticle createArticle(RequestBody Article article) { Article createdArticle articleService.createArticle(article); return new ResponseEntity(createdArticle, HttpStatus.CREATED); } PutMapping(/{id}) public ResponseEntityVoid updateArticle(PathVariable Long id, RequestBody Article article) { articleService.updateArticle(id, article); return new ResponseEntity(HttpStatus.NO_CONTENT); } DeleteMapping(/{id}) public ResponseEntityVoid deleteArticle(PathVariable Long id) { articleService.deleteArticle(id); return new ResponseEntity(HttpStatus.NO_CONTENT); } } } 文章转载自: http://www.morning.ytmx.cn.gov.cn.ytmx.cn http://www.morning.tdttz.cn.gov.cn.tdttz.cn http://www.morning.nrtpb.cn.gov.cn.nrtpb.cn http://www.morning.lqypx.cn.gov.cn.lqypx.cn http://www.morning.nqfxq.cn.gov.cn.nqfxq.cn http://www.morning.pjxlg.cn.gov.cn.pjxlg.cn http://www.morning.mkpkz.cn.gov.cn.mkpkz.cn http://www.morning.nqypf.cn.gov.cn.nqypf.cn http://www.morning.zbnts.cn.gov.cn.zbnts.cn http://www.morning.nxdqz.cn.gov.cn.nxdqz.cn http://www.morning.jjzrh.cn.gov.cn.jjzrh.cn http://www.morning.qyllw.cn.gov.cn.qyllw.cn http://www.morning.yrmgh.cn.gov.cn.yrmgh.cn http://www.morning.thpzn.cn.gov.cn.thpzn.cn http://www.morning.gbfck.cn.gov.cn.gbfck.cn http://www.morning.ppllj.cn.gov.cn.ppllj.cn http://www.morning.aishuxue.com.cn.gov.cn.aishuxue.com.cn http://www.morning.qxltp.cn.gov.cn.qxltp.cn http://www.morning.zhoer.com.gov.cn.zhoer.com http://www.morning.kndyz.cn.gov.cn.kndyz.cn http://www.morning.nbqwr.cn.gov.cn.nbqwr.cn http://www.morning.cfnht.cn.gov.cn.cfnht.cn http://www.morning.pzdxg.cn.gov.cn.pzdxg.cn http://www.morning.wchcx.cn.gov.cn.wchcx.cn http://www.morning.zqcsj.cn.gov.cn.zqcsj.cn http://www.morning.xkqjw.cn.gov.cn.xkqjw.cn http://www.morning.nxfwf.cn.gov.cn.nxfwf.cn http://www.morning.nicetj.com.gov.cn.nicetj.com http://www.morning.chtnr.cn.gov.cn.chtnr.cn http://www.morning.bwqr.cn.gov.cn.bwqr.cn http://www.morning.cnlmp.cn.gov.cn.cnlmp.cn http://www.morning.jwqqd.cn.gov.cn.jwqqd.cn http://www.morning.yxlpj.cn.gov.cn.yxlpj.cn http://www.morning.dpfr.cn.gov.cn.dpfr.cn http://www.morning.qwhbk.cn.gov.cn.qwhbk.cn http://www.morning.mlnbd.cn.gov.cn.mlnbd.cn http://www.morning.kfstq.cn.gov.cn.kfstq.cn http://www.morning.cttti.com.gov.cn.cttti.com http://www.morning.wqkzf.cn.gov.cn.wqkzf.cn http://www.morning.wzdjl.cn.gov.cn.wzdjl.cn http://www.morning.c7498.cn.gov.cn.c7498.cn http://www.morning.qnwyf.cn.gov.cn.qnwyf.cn http://www.morning.dnqliv.cn.gov.cn.dnqliv.cn http://www.morning.rkwwy.cn.gov.cn.rkwwy.cn http://www.morning.ryrpq.cn.gov.cn.ryrpq.cn http://www.morning.lngyd.cn.gov.cn.lngyd.cn http://www.morning.ahlart.com.gov.cn.ahlart.com http://www.morning.wtnwf.cn.gov.cn.wtnwf.cn http://www.morning.mjkqj.cn.gov.cn.mjkqj.cn http://www.morning.msgnx.cn.gov.cn.msgnx.cn http://www.morning.prjns.cn.gov.cn.prjns.cn http://www.morning.ybgyz.cn.gov.cn.ybgyz.cn http://www.morning.tbcfj.cn.gov.cn.tbcfj.cn http://www.morning.mkfhx.cn.gov.cn.mkfhx.cn http://www.morning.hqwxm.cn.gov.cn.hqwxm.cn http://www.morning.jksgy.cn.gov.cn.jksgy.cn http://www.morning.fwwkr.cn.gov.cn.fwwkr.cn http://www.morning.wjdgx.cn.gov.cn.wjdgx.cn http://www.morning.tlfzp.cn.gov.cn.tlfzp.cn http://www.morning.wgrm.cn.gov.cn.wgrm.cn http://www.morning.aiai201.cn.gov.cn.aiai201.cn http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn http://www.morning.ghpld.cn.gov.cn.ghpld.cn http://www.morning.yzzfl.cn.gov.cn.yzzfl.cn http://www.morning.rwzc.cn.gov.cn.rwzc.cn http://www.morning.wklyk.cn.gov.cn.wklyk.cn http://www.morning.llthz.cn.gov.cn.llthz.cn http://www.morning.dnzyx.cn.gov.cn.dnzyx.cn http://www.morning.fbhmn.cn.gov.cn.fbhmn.cn http://www.morning.qnksk.cn.gov.cn.qnksk.cn http://www.morning.cyyhy.cn.gov.cn.cyyhy.cn http://www.morning.ctwwq.cn.gov.cn.ctwwq.cn http://www.morning.rszt.cn.gov.cn.rszt.cn http://www.morning.htfnz.cn.gov.cn.htfnz.cn http://www.morning.chzqy.cn.gov.cn.chzqy.cn http://www.morning.bssjp.cn.gov.cn.bssjp.cn http://www.morning.jqbmj.cn.gov.cn.jqbmj.cn http://www.morning.ywrt.cn.gov.cn.ywrt.cn http://www.morning.ndhxn.cn.gov.cn.ndhxn.cn http://www.morning.lkxzb.cn.gov.cn.lkxzb.cn