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

花垣县建设局网站WordPress打开有广告

花垣县建设局网站,WordPress打开有广告,上海猎头公司推荐,网站建设管理总结1.新增文章分类 1.Postman登录不上,可以从头registe->login一个新的成员:注意,跳转多个url时,post/get/patch记得修改成controller类中对应方法上写的 2.postman运行成功: 但表中不更新:细节有问题: c是…

1.新增文章分类

1.Postman登录不上,可以从头registe->login一个新的成员:注意,跳转多个url时,post/get/patch记得修改成controller类中对应方法上写的

2.postman运行成功:

但表中不更新:细节有问题:

c是小写

拼写错误

3.sql层报错,已运行到mapper层->controller层没有对参数校验

参数校验:

1.pojo层

2.controller层

运行后 :

代码展示:

pojo:

package com.itheima.springbootconfigfile.pojo;import jakarta.validation.constraints.NotEmpty;
import lombok.Data;import java.time.LocalDateTime;
@Data
public class Category {private Integer id;//主键ID@NotEmptyprivate String categoryName;//分类名称@NotEmptyprivate String categoryAlias;//分类别名private Integer createUser;//创建人IDprivate LocalDateTime createTime;//创建时间private LocalDateTime updateTime;//更新时间@Overridepublic String toString() {return "Category{" +"id=" + id +", categoryName='" + categoryName + '\'' +", categoryAlias='" + categoryAlias + '\'' +", createUser=" + createUser +", createTime=" + createTime +", updateTime=" + updateTime +'}';}public Category() {}public Category(Integer id, String categoryName, String categoryAlias, Integer createUser, LocalDateTime createTime, LocalDateTime updateTime) {this.id = id;this.categoryName = categoryName;this.categoryAlias = categoryAlias;this.createUser = createUser;this.createTime = createTime;this.updateTime = updateTime;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getCategoryName() {return categoryName;}public void setCategoryName(String categoryName) {this.categoryName = categoryName;}public String getCategoryAlias() {return categoryAlias;}public void setCategoryAlias(String categoryAlias) {this.categoryAlias = categoryAlias;}public Integer getCreateUser() {return createUser;}public void setCreateUser(Integer createUser) {this.createUser = createUser;}public LocalDateTime getCreateTime() {return createTime;}public void setCreateTime(LocalDateTime createTime) {this.createTime = createTime;}public LocalDateTime getUpdateTime() {return updateTime;}public void setUpdateTime(LocalDateTime updateTime) {this.updateTime = updateTime;}
}

controller:

package com.itheima.springbootconfigfile.controller;import com.itheima.springbootconfigfile.pojo.Category;
import com.itheima.springbootconfigfile.pojo.Result;
import com.itheima.springbootconfigfile.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;//文章分类
@RestController
@RequestMapping("/category")
public class CategoryController {@Autowiredprivate CategoryService categoryService;//新增文章分类@PostMapping("/add")public Result add(@RequestBody @Validated Category category){categoryService.add(category);return  Result.success();}}

categoryServiceIMpl:

package com.itheima.springbootconfigfile.service.impl;import com.itheima.springbootconfigfile.mapper.CategoryMapper;
import com.itheima.springbootconfigfile.pojo.Category;
import com.itheima.springbootconfigfile.service.CategoryService;
import com.itheima.springbootconfigfile.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.time.LocalDateTime;
import java.util.Map;@Service
public class CategoryServiceImpl implements CategoryService {@Autowiredprivate CategoryMapper categoryMapper;@Overridepublic void add(Category category) {category.setCreateTime(LocalDateTime.now());category.setUpdateTime(LocalDateTime.now());Map<String,Object> map= ThreadLocalUtil.get();Integer userId= (Integer) map.get("id");category.setCreateUser(userId);//连接user表中的id,即userId=createUser=idcategoryMapper.add(category);}
}

categoryMapper:

package com.itheima.springbootconfigfile.mapper;import com.itheima.springbootconfigfile.pojo.Category;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface CategoryMapper {@Insert("insert into category (categoryName,categoryAlias,createUser,createTime,updateTime) values (#{categoryName},#{categoryAlias},#{createUser},now(),now())")void add(Category category);
}


2.文章分类列表(显示当前用户已有的所有文章分类)

代码展示:

controller:

 //文章分类列表@GetMapping()public  Result<List<Category>> list(){List<Category> cs=categoryService.list();return Result.success(cs);}

categoryServiceImpl:

 @Overridepublic List<Category> list() {Map<String,Object> map=ThreadLocalUtil.get();Integer userId= (Integer) map.get("id");return categoryMapper.list(userId);}

categoryMapper:

  @Select("select * from category where createUser=#{userId}")List<Category> list(Integer userId);

 createUser和userId:

运行:

优化:时间表达不是常规表达

对属性的限制可加在controller类的方法的参数上 或 实体类上

修改:

@Data
public class Category {private Integer id;//主键ID@NotEmptyprivate String categoryName;//分类名称@NotEmptyprivate String categoryAlias;//分类别名private Integer createUser;//创建人ID@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")private LocalDateTime createTime;//创建时间@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")private LocalDateTime updateTime;//更新时间

运行:

回忆下User类对属性的注解:

@Data
public class User {
    @NotNull
    private Integer id;//主键ID
    private String username;//用户名
    @JsonIgnore
    //当前对象转变为json字符串时,忽略password,最终的json 字符串就无password这个属性
    private String password;//密码
    @NotEmpty
    @Pattern(regexp = "^\\S{1,10}$")
    private String nickname;//昵称
    @NotEmpty
    @Email
    private String email;//邮箱


3.获取文章分类详情 

代码展示:

controller:

  //获取文章详情@GetMapping("/detail")public Result<Category> detail(Integer id){Category c=categoryService.findById(id);return Result.success(c);}

categoryServiceImpl:

  @Overridepublic Category findById(Integer id) {Category c =categoryMapper.findById(id);return c;}

categoryMapper:

   @Select("select * from category where id=#{id}")Category findById(Integer id);

运行: 

可优化:category表和user表是联通的,但该方法没要求必须是本用户才可以查询文章分类详情,即可以查到其他用户的文章分类

但若以文章分类是公共的,也可以不限制


4.更新文章分类 

代码展示:

//更新文章分类
@PutMapping("update")
public Result update(@RequestBody @Validated Category category){categoryService.update(category);return Result.success();
}
 @Overridepublic void update(Category category) {category.setUpdateTime(LocalDateTime.now());categoryMapper.update(category);}

 @Update("update category set categoryName=#{categoryName},categoryAlias=#{categoryAlias},updateTime=#{updateTime} where id=#{id}")void update(Category category);
 @NotNullprivate Integer id;//主键ID

运行:

postman修改后,idea重新运行才会成功

可优化:createUser=userId

思考:

为什么不能这样写:

@PutMapping("update")
public Result<Category> update(Integer id){Category c= categoryService.update(id);return Result.success(c);
}

 运行报错:

问题的核心在于 CategoryMapper.update 方法的返回类型不被 MyBatis 支持。MyBatis 对于 updatedeleteinsert 等操作的返回类型通常是 int,表示影响的行数,而不是返回一个 POJO 类型。 


5.BUG修改 

bug描述:

第4中在category类增加了

再运行1.add,报错:


文章转载自:

http://W6AEuvaw.tLyms.cn
http://mRCSjoNe.tLyms.cn
http://9eLruG4n.tLyms.cn
http://3cTaYZZs.tLyms.cn
http://mBP7ghag.tLyms.cn
http://IKQM4UZj.tLyms.cn
http://DO4rFNFW.tLyms.cn
http://uYTz95tS.tLyms.cn
http://tdUiwEE5.tLyms.cn
http://h7dIJzRI.tLyms.cn
http://xJQKrWOq.tLyms.cn
http://uyfls0u3.tLyms.cn
http://GVTGIuVL.tLyms.cn
http://i2phhLF7.tLyms.cn
http://ys9YR5DA.tLyms.cn
http://xKmG9Ce5.tLyms.cn
http://FJ7WMAmn.tLyms.cn
http://h6tIakpv.tLyms.cn
http://bN02Abzw.tLyms.cn
http://aPOzGtPe.tLyms.cn
http://ZbwFTEbG.tLyms.cn
http://bCe9DYgr.tLyms.cn
http://lw5gehwW.tLyms.cn
http://YMqzMYcA.tLyms.cn
http://BuzfZQb4.tLyms.cn
http://IPZG9FoN.tLyms.cn
http://URIY8rtH.tLyms.cn
http://f7yZNra5.tLyms.cn
http://bAkZNKKb.tLyms.cn
http://kD4bAR7n.tLyms.cn
http://www.dtcms.com/wzjs/629154.html

相关文章:

  • 中国建筑股票成都搜索引擎优化推广维护
  • 网站 规划方案外链优化
  • 网站链接跳转如何做做网站被坑
  • 自己做菠菜网站昆山建设局网站表格下
  • 哪些网站是由wordpress做的性价比最高网站建设哪里好
  • 梧州做网站网页设计师行业分析
  • 万网 网站建设南县网站设计
  • 外地公司做的网站能备案网络服务提供者发现未成年人
  • 怎么建设淘客自己的网站_wordpress 代码臃肿
  • 手机网站php开发用手机搭建wordpress
  • 正邦设计广州分公司北京seo公司哪家好
  • 做一个和淘宝一样的网站要多少钱app开发定制公司哪家
  • 做包装设计的网站网站备案管理系统网站
  • 报名系统网站开发天猫网站平面广告
  • 门户网站建设定制中国形象设计网
  • 南通网站定制方案建网站卖多少钱
  • 网站开发具体的工作内容网站后台编辑器下载
  • 仿阿里百秀网站模板网站模板抄袭
  • 电子商务网站开发指南网站建设与规划实验总结
  • 南昌网站建设WordPress与其它
  • 湛江外包做网站wordpress 视频边栏
  • 关于做书的网站做企业网站的架构图
  • 哪个网站有淘宝做图的素材WordPress换域名更新
  • 重庆展示型网站制作上海发布首页
  • 网站色彩的应用建设工商联网站的意义
  • 统计网站访客人数天猫购物商城
  • 如何用书签 做网站接口推广软文营销案例
  • 石家庄建设信息网官方网站网站建设服务器有哪些
  • 网站类型案例ups国际快递网站建设
  • 网站特效模板下载网站建设公司汉狮网络