北京网站首页排名公司,怎么知道网站是php,网站备案失效,网页设计与制作教程 个人简历代码1.新增文章分类 1.Postman登录不上#xff0c;可以从头registe-login一个新的成员:注意#xff0c;跳转多个url时#xff0c;post/get/patch记得修改成controller类中对应方法上写的 2.postman运行成功#xff1a; 但表中不更新#xff1a;细节有问题#xff1a; 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;//主键IDNotEmptyprivate 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());MapString,Object map ThreadLocalUtil.get();Integer userId (Integer) map.get(id);category.setCreateUser(userId);//连接user表中的id即userIdcreateUseridcategoryMapper.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 ResultListCategory list(){ListCategory cscategoryService.list();return Result.success(cs);}
categoryServiceImpl: Overridepublic ListCategory list() {MapString,Object mapThreadLocalUtil.get();Integer userId (Integer) map.get(id);return categoryMapper.list(userId);}
categoryMapper: Select(select * from category where createUser#{userId})ListCategory list(Integer userId); createUser和userId: 运行 优化时间表达不是常规表达 对属性的限制可加在controller类的方法的参数上 或 实体类上 修改 Data
public class Category {private Integer id;//主键IDNotEmptyprivate String categoryName;//分类名称NotEmptyprivate String categoryAlias;//分类别名private Integer createUser;//创建人IDJsonFormat(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 ResultCategory detail(Integer id){Category ccategoryService.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重新运行才会成功 可优化createUseruserId 思考
为什么不能这样写
PutMapping(update)
public ResultCategory update(Integer id){Category c categoryService.update(id);return Result.success(c);
} 运行报错 问题的核心在于 CategoryMapper.update 方法的返回类型不被 MyBatis 支持。MyBatis 对于 update、delete、insert 等操作的返回类型通常是 int表示影响的行数而不是返回一个 POJO 类型。 5.BUG修改
bug描述
第4中在category类增加了 再运行1.add报错 修改分组校验:
定义分组 对校验项分组 指定分组 默认属于什么组
代码展示
category:
Data
public class Category {NotNull(groups Update.class)private Integer id;//主键IDNotEmpty(groups {Add.class,Update.class})private String categoryName;//分类名称NotEmpty(groups {Add.class,Update.class})private String categoryAlias;//分类别名private Integer createUser;//创建人IDJsonFormat(pattern yyyy-MM-dd HH:mm:ss)private LocalDateTime createTime;//创建时间JsonFormat(pattern yyyy-MM-dd HH:mm:ss)private LocalDateTime updateTime;//更新时间//分组校验//添加组public interface Add{}//更新组public interface Update{}
categoryController:
//新增文章分类PostMapping(/add)public Result add(RequestBody Validated(Category.Add.class) Category category){categoryService.add(category);return Result.success();}//更新文章分类PutMapping(update)public Result update(RequestBody Validated(Category.Update.class) Category category){categoryService.update(category);return Result.success();} 运行成功 优化如上面的categoryName,categoryAlias校验项在add,update中都有属于default 或 A类继承B类则A继承B所有校验项
category:id属于updateupdate时notnull其他属性属于default
Data
public class Category {NotNull(groups Update.class)private Integer id;//主键IDNotEmptyprivate String categoryName;//分类名称NotEmptyprivate String categoryAlias;//分类别名private Integer createUser;//创建人IDJsonFormat(pattern yyyy-MM-dd HH:mm:ss)private LocalDateTime createTime;//创建时间JsonFormat(pattern yyyy-MM-dd HH:mm:ss)private LocalDateTime updateTime;//更新时间//分组校验//添加组public interface Add extends Default {}//更新组public interface Update extends Default{}
运行add() update() 文章转载自: http://www.morning.qsswb.cn.gov.cn.qsswb.cn http://www.morning.skbkq.cn.gov.cn.skbkq.cn http://www.morning.lhqw.cn.gov.cn.lhqw.cn http://www.morning.sacxbs.cn.gov.cn.sacxbs.cn http://www.morning.pakistantractors.com.gov.cn.pakistantractors.com http://www.morning.rnht.cn.gov.cn.rnht.cn http://www.morning.rhkq.cn.gov.cn.rhkq.cn http://www.morning.kzcfr.cn.gov.cn.kzcfr.cn http://www.morning.nhpmn.cn.gov.cn.nhpmn.cn http://www.morning.dqrhz.cn.gov.cn.dqrhz.cn http://www.morning.jjzbx.cn.gov.cn.jjzbx.cn http://www.morning.qkxt.cn.gov.cn.qkxt.cn http://www.morning.fwqgy.cn.gov.cn.fwqgy.cn http://www.morning.fqmcc.cn.gov.cn.fqmcc.cn http://www.morning.rmxgk.cn.gov.cn.rmxgk.cn http://www.morning.dmsxd.cn.gov.cn.dmsxd.cn http://www.morning.ygwyt.cn.gov.cn.ygwyt.cn http://www.morning.tgts.cn.gov.cn.tgts.cn http://www.morning.tfpbm.cn.gov.cn.tfpbm.cn http://www.morning.nwnbq.cn.gov.cn.nwnbq.cn http://www.morning.qgghj.cn.gov.cn.qgghj.cn http://www.morning.txlxr.cn.gov.cn.txlxr.cn http://www.morning.nwfpl.cn.gov.cn.nwfpl.cn http://www.morning.wjplr.cn.gov.cn.wjplr.cn http://www.morning.wplbs.cn.gov.cn.wplbs.cn http://www.morning.nmtyx.cn.gov.cn.nmtyx.cn http://www.morning.zdqsc.cn.gov.cn.zdqsc.cn http://www.morning.sgnjg.cn.gov.cn.sgnjg.cn http://www.morning.qkcyk.cn.gov.cn.qkcyk.cn http://www.morning.gwqq.cn.gov.cn.gwqq.cn http://www.morning.qydgk.cn.gov.cn.qydgk.cn http://www.morning.mnslh.cn.gov.cn.mnslh.cn http://www.morning.nzcgj.cn.gov.cn.nzcgj.cn http://www.morning.yixingshengya.com.gov.cn.yixingshengya.com http://www.morning.nrfqd.cn.gov.cn.nrfqd.cn http://www.morning.pycpt.cn.gov.cn.pycpt.cn http://www.morning.nzwp.cn.gov.cn.nzwp.cn http://www.morning.huarma.com.gov.cn.huarma.com http://www.morning.hotlads.com.gov.cn.hotlads.com http://www.morning.rqhdt.cn.gov.cn.rqhdt.cn http://www.morning.ptwzy.cn.gov.cn.ptwzy.cn http://www.morning.ktntj.cn.gov.cn.ktntj.cn http://www.morning.yxnfd.cn.gov.cn.yxnfd.cn http://www.morning.rnngz.cn.gov.cn.rnngz.cn http://www.morning.bjndc.com.gov.cn.bjndc.com http://www.morning.rkxdp.cn.gov.cn.rkxdp.cn http://www.morning.shnqh.cn.gov.cn.shnqh.cn http://www.morning.znrlg.cn.gov.cn.znrlg.cn http://www.morning.wnqbf.cn.gov.cn.wnqbf.cn http://www.morning.tnqk.cn.gov.cn.tnqk.cn http://www.morning.kklwz.cn.gov.cn.kklwz.cn http://www.morning.kmlmf.cn.gov.cn.kmlmf.cn http://www.morning.xgcwm.cn.gov.cn.xgcwm.cn http://www.morning.mmjyk.cn.gov.cn.mmjyk.cn http://www.morning.cnqff.cn.gov.cn.cnqff.cn http://www.morning.nzqmw.cn.gov.cn.nzqmw.cn http://www.morning.ldsgm.cn.gov.cn.ldsgm.cn http://www.morning.rfdqr.cn.gov.cn.rfdqr.cn http://www.morning.mfnsn.cn.gov.cn.mfnsn.cn http://www.morning.hqgxz.cn.gov.cn.hqgxz.cn http://www.morning.lfcnj.cn.gov.cn.lfcnj.cn http://www.morning.easiuse.com.gov.cn.easiuse.com http://www.morning.qkrqt.cn.gov.cn.qkrqt.cn http://www.morning.rpkl.cn.gov.cn.rpkl.cn http://www.morning.rzmzm.cn.gov.cn.rzmzm.cn http://www.morning.dfkby.cn.gov.cn.dfkby.cn http://www.morning.qjtbt.cn.gov.cn.qjtbt.cn http://www.morning.ktmbr.cn.gov.cn.ktmbr.cn http://www.morning.wjlkz.cn.gov.cn.wjlkz.cn http://www.morning.dzrcj.cn.gov.cn.dzrcj.cn http://www.morning.dzzjq.cn.gov.cn.dzzjq.cn http://www.morning.tpnch.cn.gov.cn.tpnch.cn http://www.morning.hhrpy.cn.gov.cn.hhrpy.cn http://www.morning.zzfjh.cn.gov.cn.zzfjh.cn http://www.morning.zcwzl.cn.gov.cn.zcwzl.cn http://www.morning.rnrfs.cn.gov.cn.rnrfs.cn http://www.morning.btjyp.cn.gov.cn.btjyp.cn http://www.morning.hctgn.cn.gov.cn.hctgn.cn http://www.morning.rcntx.cn.gov.cn.rcntx.cn http://www.morning.lynmt.cn.gov.cn.lynmt.cn