中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

做宣傳圖冊在什么網(wǎng)站浙江企業(yè)seo推廣

做宣傳圖冊在什么網(wǎng)站,浙江企業(yè)seo推廣,做推送的網(wǎng)站推薦,自己做網(wǎng)站編程目錄 發(fā)布文章 接口文檔 業(yè)務(wù)實現(xiàn) 自定義參數(shù)校驗 項目參數(shù)要求 實現(xiàn)思路 實現(xiàn)步驟 文章列表(條件分頁) 接口文檔 業(yè)務(wù)實現(xiàn) mapper映射 更新文章 接口文檔 業(yè)務(wù)實現(xiàn) 獲取文章詳情 接口文檔 業(yè)務(wù)實現(xiàn) 刪除文章 接口文檔 業(yè)務(wù)實現(xiàn) 文章管理業(yè)務(wù)表結(jié)構(gòu)…

目錄

發(fā)布文章

接口文檔

?業(yè)務(wù)實現(xiàn)

自定義參數(shù)校驗

項目參數(shù)要求?

實現(xiàn)思路?

實現(xiàn)步驟

文章列表(條件分頁)

接口文檔?

業(yè)務(wù)實現(xiàn)?

mapper映射?

更新文章

?接口文檔

?業(yè)務(wù)實現(xiàn)

獲取文章詳情?

接口文檔?

業(yè)務(wù)實現(xiàn)?

刪除文章?

接口文檔?

業(yè)務(wù)實現(xiàn)?


文章管理業(yè)務(wù)表結(jié)構(gòu)

發(fā)布文章

接口文檔

?業(yè)務(wù)實現(xiàn)

創(chuàng)建ArticleController類并完成請求的方法

@RestController
@RequestMapping("/article")
public class ArticleController {@Autowiredprivate ArticleService articleService; //注入ArticleService接口@PostMappingpublic Result add(@RequestBody Article article){articleService.add(article);return Result.success();}
}

創(chuàng)建ArticleService接口并完成方法

public interface ArticleService {//新增文章void add(Article article);
}

創(chuàng)建ArticleServiceimpl接口實現(xiàn)類并完成方法

@Service
public class ArticleServiceimpl implements ArticleService {@Autowiredprivate ArticleMapper articleMapper; //注入ArticleMapper接口@Overridepublic void add(Article article) {//補(bǔ)充id屬性值 用于添加到create_usera字段中Map<String,Object> map = ThreadLocalUtil.get();Integer id = (Integer) map.get("id");article.setCreateUser(id);articleMapper.add(article);}
}

創(chuàng)建ArticleMapper接口并完成方法

@Mapper
public interface ArticleMapper {//添加文章@Insert("insert into article(title,content,cover_img,state,category_id,create_user,create_time,update_time)" +" values(#{title},#{content},#{coverImg},#{state},#{categoryId},#{createUser},now(),now())")void add(Article article);
}

運(yùn)行請求查看?

?數(shù)據(jù)庫中查看已添加成功

自定義參數(shù)校驗

? ? 已有的注解不能滿足所有的校驗需求,特殊的情況需要自定義校驗(自定義校驗注解)?

項目參數(shù)要求?

實現(xiàn)思路?

  1. 自定義注解State
  2. 自定義校驗數(shù)據(jù)的類StateValidation 實現(xiàn)ConstraintValidator接口
  3. 在需要校驗的地方使用自定義注解?

?實現(xiàn)步驟

?在Article實體類中對能滿足校驗要求的成員變量進(jìn)行校驗

在ArticleController接口中對方法參數(shù)使用@Validated注解?

但對于state變量參數(shù)已有的注解不能滿足所有的校驗需求,所以需要對其使用自定義參數(shù)校驗。

新建anno包,在包下新定義State注解,并完善定義注解的代碼

@Documented //元注解 用于抽取自定義的注解到幫助文檔
@Target({ElementType.FIELD}) //元注解 自定義的標(biāo)注用在哪些地方 FIELD表示在變量屬性上標(biāo)注
@Retention(RetentionPolicy.RUNTIME) //元注解 用于標(biāo)識自定義的注解會在哪一階段保留 RUNTIME表示運(yùn)行階段
@Constraint(validatedBy = {}) //用于指定誰給自定義的注解定義參數(shù)校驗規(guī)則
public @interface State {//message用于提供校驗失敗后的提示信息String message() default "'state參數(shù)的值只能是已發(fā)布或者草稿";//用于指定分組Class<?>[] groups() default {};//負(fù)載 獲取到State注解的附如信息Class<? extends Payload>[] payload() default {};
}

新建validation包,在包下定義StateValidation校驗規(guī)則類,并完善校驗規(guī)則代碼

public class StateValidation implements ConstraintValidator<State,String> { //接口的泛型:<會給哪個注解提供校驗規(guī)則,校驗的數(shù)據(jù)類型>/***參數(shù)解釋:** value:將來要校驗的數(shù)據(jù)* context* return: 如果返回false則校驗不通過, 如果返回true則校驗通過*/@Overridepublic boolean isValid(String value, ConstraintValidatorContext context) {//提供校驗規(guī)則if(value == null){return false;}if(value.equals("已發(fā)布") || value.equals("草稿")){return true;}return false; //其余情況返回false}
}

?再回到State注解中完善要指定的校驗規(guī)則

到實體類中在需要的成員變量使用該自定義注解用于達(dá)到注解參數(shù)校驗的目的

文章列表(條件分頁)

接口文檔?

業(yè)務(wù)實現(xiàn)?

創(chuàng)建PageBean實體類?

//分頁返回結(jié)果對象
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageBean <T>{private Long total;//總條數(shù)private List<T> items;//當(dāng)前頁數(shù)據(jù)集合
}

編寫ArticleController中的請求的方法

    @GetMappingpublic Result<PageBean<Article>> list(Integer pageNum,Integer pageSize,  //使用@RequestParam(required = false)可以使參數(shù)設(shè)置為可傳入也可不傳入@RequestParam(required = false) String categoryId,@RequestParam(required = false) String state){PageBean<Article> pb = articleService.list(pageNum,pageSize,categoryId,state);return Result.success(pb);}

編寫ArticleService接口的方法

    //條件分頁列表查詢PageBean<Article> list(Integer pageNum, Integer pageSize, String categoryId, String state);
}

在pom文件導(dǎo)入pagehelper插件依賴用于完成分頁查詢?

        <!-- pagehelper插件--><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.4.6</version></dependency>

編寫ArticleServiceimpl接口實現(xiàn)類的方法

    @Overridepublic PageBean<Article> list(Integer pageNum, Integer pageSize, String categoryId, String state) {//定義pageBean對象PageBean<Article> pb = new PageBean<>();//開啟分頁查詢 PageHelperPageHelper.startPage(pageNum,pageSize);//添加id參數(shù) 調(diào)用mapper接口的方法Map<String,Object> map = ThreadLocalUtil.get();Integer id = (Integer) map.get("id");List<Article> arlist = articleMapper.list(id,categoryId,state);//page中提供了方法可以獲取pagehelper分頁查詢后,得到的總記錄條數(shù)和當(dāng)前頁數(shù)Page<Article> p = (Page<Article>) arlist;//將page對象獲取的記錄和條數(shù)添加到pagebean對象中pb.setTotal(p.getTotal());pb.setItems(p.getResult());return  pb; //返回pagebean對象}

編寫ArticleMapper接口的方法?

    //條件分頁列表查詢List<Article> list(Integer id, String categoryId, String state);

mapper映射?

由于參數(shù)?categoryId和state參數(shù)為非必填,所以這里sql需要用到sql映射文件來寫動態(tài)sql

在resource目錄下創(chuàng)建和mapper包一樣的結(jié)構(gòu)目錄

目錄結(jié)構(gòu)要和mapper接口目錄相同

配置文件名稱要和接口名稱相同

編寫sql映射配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!-- 命名空間要和mapper接口的路徑全類名要相同   -->
<mapper namespace="com.springboot.springboot_test.mapper.ArticleMapper">
<!-- 編寫動態(tài)sql
select標(biāo)簽的
id參數(shù)要和mapper接口的方法名稱一致
resultType 返回值類型要和實體類名稱一致--><select id="list" resultType="com.springboot.springboot_test.pojo.Article">select * from article<where><if test="categoryId != null">category_id = #{categoryId}</if><if test="state != null">and state = #{state}</if>and create_user= #{id}</where></select></mapper>

運(yùn)行請求查看

?

更新文章

?接口文檔

?業(yè)務(wù)實現(xiàn)

編寫ArticleController中的請求的方法

    @PutMappingpublic Result update(@RequestBody @Validated Article article){articleService.update(article);return Result.success();}

編寫ArticleService接口的方法

    //更新文章void update(Article article);

編寫ArticleServiceimpl接口實現(xiàn)類的方法

    @Overridepublic void update(Article article) {articleMapper.update(article);}

編寫ArticleMapper接口的方法

    //更新文章@Update("update article set title = #{title},content = #{content},cover_img = #{coverImg},state = #{state}, " +"category_id = #{categoryId},update_time = now() where id = #{id}")void update(Article article);

運(yùn)行請求查看

?

獲取文章詳情?

接口文檔?

業(yè)務(wù)實現(xiàn)?

編寫ArticleController中的請求的方法

    @GetMapping("/detail")public Result detail(Integer id){Article ar = articleService.findById(id);return Result.success(ar);}

編寫ArticleService接口的方法

    //查看文章詳情Article findById(Integer id);

編寫ArticleServiceimpl接口實現(xiàn)類的方法

    @Overridepublic Article findById(Integer id) {Article ar = articleMapper.findById(id);return ar;}

編寫ArticleMapper接口的方法

    //查看文章詳情@Select("select * from article where id =#{id}")Article findById(Integer id);

?運(yùn)行請求查看

刪除文章?

接口文檔?

業(yè)務(wù)實現(xiàn)?

編寫ArticleController中的請求的方法

    @DeleteMappingpublic Result delete(Integer id){articleService.delete(id);return Result.success();}

編寫ArticleService接口的方法

    //刪除文章void delete(Integer id);

編寫ArticleServiceimpl接口實現(xiàn)類的方法

    @Overridepublic void delete(Integer id) {articleMapper.delete(id);}

編寫ArticleMapper接口的方法

    //刪除文章@Delete("delete from article where id = #{id}")void delete(Integer id);

運(yùn)行請求查看

?

?

http://www.risenshineclean.com/news/66145.html

相關(guān)文章:

  • 自己做開獎網(wǎng)站seo外包方案
  • 阿里云做網(wǎng)站經(jīng)費(fèi)seo優(yōu)化網(wǎng)頁
  • 武漢做網(wǎng)站制作創(chuàng)建網(wǎng)站免費(fèi)注冊
  • 阿里云搭建自己的網(wǎng)站seo崗位是什么意思
  • smarty做網(wǎng)站百度圖片搜索引擎入口
  • 手機(jī)微網(wǎng)站建設(shè)方案網(wǎng)站怎么添加外鏈
  • 網(wǎng)站定向推送怎么做關(guān)鍵詞排名零芯互聯(lián)排名
  • 深圳個人外貿(mào)網(wǎng)站建排名優(yōu)化哪家好
  • 深圳建設(shè)局網(wǎng)站天津百度整站優(yōu)化服務(wù)
  • 網(wǎng)站右側(cè) 回到頂部站長工具流量統(tǒng)計
  • 仿站 做網(wǎng)站免費(fèi)推廣網(wǎng)站排行榜
  • 好用的日本ip地址seo優(yōu)化要做什么
  • 溫州網(wǎng)站推廣站建設(shè)全媒體廣告策劃營銷
  • 網(wǎng)站建設(shè)發(fā)票內(nèi)容蘇州網(wǎng)站制作開發(fā)公司
  • 惠州高端網(wǎng)站建設(shè)寵物美容師寵物美容培訓(xùn)學(xué)校
  • 如何建設(shè)網(wǎng)站平臺企業(yè)seo優(yōu)化服務(wù)
  • b2b網(wǎng)站怎么做濟(jì)南網(wǎng)站優(yōu)化
  • 工信部做網(wǎng)站認(rèn)證嗎杭州優(yōu)化公司多少錢
  • 企業(yè)做網(wǎng)站屬于廣告宣傳費(fèi)嗎sem投放
  • 天津網(wǎng)站建設(shè)交易公司網(wǎng)站建站要多少錢
  • 網(wǎng)站名稱備案青島神馬排名優(yōu)化
  • 山東公司網(wǎng)站開發(fā)外鏈工廠 外鏈
  • wordpress怎么導(dǎo)入自己的phpseo網(wǎng)站優(yōu)化外包
  • 自己做網(wǎng)站需要服務(wù)器嗎google付費(fèi)推廣
  • flash 網(wǎng)站頭部東莞做網(wǎng)站公司電話
  • wordpress 輪播圖插件下載惠州抖音seo
  • 網(wǎng)站 http 狀態(tài)碼返回值 301百度在線識圖查圖片
  • 怎么用自己的主機(jī)做網(wǎng)站服務(wù)器嗎企業(yè)宣傳片文案
  • 美國做ppt的網(wǎng)站有人百度看片嗎
  • 公司網(wǎng)站制作哪家公司好百度網(wǎng)站app下載