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

云主机建网站教程wordpress 主题推荐

云主机建网站教程,wordpress 主题推荐,网站开发需会的课程,棋牌游戏软件开发SpringBootWeb项目 TILAS智能学习辅助系统 需求 部门管理 查询部门列表 删除部门 新增部门 修改部门 员工管理 查询员工列表(分页) 删除员工 新增员工 修改员工 准备工作 导入依赖 web(2.7.6) mybatis mysql驱动 lombok 准备好包结构 Controller->Servi…

SpringBootWeb项目

TILAS智能学习辅助系统

需求

部门管理

查询部门列表
删除部门
新增部门
修改部门

员工管理

查询员工列表(分页)
删除员工
新增员工
修改员工

准备工作

导入依赖

web(2.7.6)

mybatis

mysql驱动

lombok

准备好包结构

Controller->Service->Mapper->Pojo

controller

@Controller
public interface DeptController{
}@Controller
public interface EmpController {
}

mapper

@Mapper
public interface DeptMapper {
}
@Mapper
public interface EmpMapper {
}

service/serviceImpl

@Service
public interface DeptService {
}
@Service
public interface EmpService {
}
@Slf4j
@Service
public class DeptServiceImpl {
}
@Slf4j
@Service
public class EmpServiceImpl {
}
创建数据库表和对应的实体类
@Data
public class Dept {private Integer id;private String username;private String password;private String name;private Short gender;private String image;private Short job;private LocalDate entrydate;private Integer deptId;private LocalDateTime createTime;private LocalDateTime updateTime;
}@Data
public class Emp {private Integer id;private String name;private LocalDateTime createTime;private LocalDateTime updateTime;
}
在配置文件中引入数据库连接
server.port=8080
#下面这些内容是为了让MyBatis映射
#指定Mybatis的Mapper文件
mybatis.mapper-locations=classpath:mappers/*xml
#指定Mybatis的实体目录
mybatis.type-aliases-package=com.example.tlias.mybatis.entityspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/Tlias_db
spring.datasource.username=root
spring.datasource.password=ljymysqlpwd
#开启日志
mybatis.configuration.logimpl=org.apache.ibatis.logging.stdout.StdOutImpl
#开启字段到实体类的驼峰映射
mybatis.configuration.map-underscore-to-camel-case=true

开发规范

基于前后端分离模式进行开发

定义主流的REST风格API接口进行交互

REST:(Representational State Transfer)表现形式状态转换,一种软件架构风格
url/aaa/1 GET:查询
url/aaa   POST:新增
url/aaa	  PUT:修改
url/aaa/1 DELETE

通过请求方式的不同进行不同操作

在@RequestMapping()中设置method = {RequestMethod.请求方式} RequestMethod是一个枚举类型

或者直接使用

@GetMapping

@PostMapping

@PutMapping

@DeleteMapping

开发流程

根据如下流程进行开发

查看页面原型明确需求

阅读接口文档

思路分析

接口开发:开发后台业务功能(功能按接口划分)

接口测试;通过Postman进行接口测试

前后端联调:和前端工程一起进行测试

功能实现

1,部门管理

查询部门

无需分页

请求路径:/depts

请求方式:GET

//控制层
@GetMapping("/depts")Result getDept();@AutowiredDeptService deptService;@Overridepublic Result getDept() {return Result.success(deptService.selectDept());}//业务层
List<Dept> selectDept();@Autowiredprivate DeptMapper deptMapper;@Overridepublic List<Dept> selectDept(){List<Dept> deptList = deptMapper.selectDept();return deptList;}//持久层
@Select("select * from dept")List<Dept> selectDept();
删除部门

前端传递ID,后端删除对应数据

请求路径:/depts/{id}

请求方式:DELETE

//控制层
//接收路径参数
@DeleteMapping("/depts/{id}")Result DeleteDept(@PathVariable Integer id);@AutowiredDeptService deptService;@Overridepublic Result DeleteDept(Integer id) {deptService.deleteDept(id);return Result.success();}//业务层
void deleteDept(Integer id);@Autowiredprivate DeptMapper deptMapper;@Overridepublic void deleteDept(Integer id) {deptMapper.deleteDept(id);}//持久层
@Delete("delete from dept where id = #{id}")void deleteDept(@Param("id") Integer id);
新增部门

前端输入部门名称,后端创建部门保存到数据库

请求路径:/depts

请求方式:POST

//控制层
//接收JSON参数,使用@RequestBody进行映射
@PostMapping("/depts")Result PostDept(@RequestBody Dept dept);@AutowiredDeptService deptService;@Overridepublic Result PostDept(@RequestBody Dept dept) {deptService.insertDept(dept);return Result.success();}//业务层
void insertDept(Dept dept);@Autowiredprivate DeptMapper deptMapper;@Overridepublic void insertDept(Dept dept) {dept.setCreateTime(LocalDateTime.now());dept.setUpdateTime(LocalDateTime.now());deptMapper.insertDept(dept);}//持久层
@Insert("insert into dept (id, name, create_time, update_time) values (null,#{name},#{createTime},#{updateTime})")void insertDept(Dept dept);
修改部门

先通过selectById进行数据回填,再通过updateDept进行数据修改

//控制层@PutMapping("/depts")Result PutDept(@RequestBody Dept dept);@GetMapping("/depts/{id}")Result getDeptByID(@PathVariable Integer id);@AutowiredDeptService deptService;@Overridepublic Result PutDept(Dept dept) {deptService.putDept(dept);return Result.success();}@Overridepublic Result getDeptByID(Integer id) {return Result.success(deptService.selectDeptByID(id));}//业务层void putDept(Dept dept);Dept selectDeptByID(Integer id);@Autowiredprivate DeptMapper deptMapper;@Overridepublic void putDept(Dept dept) {dept.setUpdateTime(LocalDateTime.now());deptMapper.putDept(dept);}@Overridepublic Dept selectDeptByID(Integer id) {return deptMapper.selectDeptByID(id);}//持久层//修改部门@Update("update dept set name = #{name} where id = #{id}")void putDept(Dept dept);//查询部门数据byID@Select("select * from dept where id = #{id}")Dept selectDeptByID(Integer id);

员工管理

分页查询

使用sql中的LIMIT语句

前端发送查询第几页,后端根据前端返回的页码进行计算对应显示的数据

参数传递:页码page,每页展示数pageSize

后端响应:当前页展示的数据,总共的记录数,封装到对象中以json格式数据进行响应回复

//控制层
@GetMapping("/emps")
Result pageSelect(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer num);@Override
public Result pageSelect(@RequestParam(defaultValue = "1") Integer 		page, @RequestParam(defaultValue = "10") Integer num) {PageBean bean = empService.selectPage(page,num);return Result.success(bean);
}//服务层
PageBean selectPage(Integer page, Integer num);
//返回一个pagebean对象,封装了数据总条数和数据列表@Overridepublic PageBean page(String name, Short gender, LocalDate begin, LocalDate end, Integer page, Integer num) {List<Emp> empList = empMapper.selectEmp();List<Emp> empList = empMapper.selectEmi(name,gender,begin,end);return new pageBean(count,emplist);//在持久层中计算总数据条数}//持久层
@Select("select * from emp limit #{index},#{num}")List<Emp> selectPage(@Param("index") Integer index, @Param("num") Integer num);
分页插件

PageHelper,Mybatis的一款分页插件,简化了在Mapper层手动分页的操作,直接使用列表查询,在Service层调用mapper方法设置分页参数.在查询之后解析分页结果,最后封装到PageBean对象中返回即可.

仅在服务层中不同,可以

//服务层
PageBean selectPage(Integer page, Integer num);
//返回一个pagebean对象,封装了数据总条数和数据列表@Overridepublic PageBean page(String name, Short gender, LocalDate begin, LocalDate end, Integer page, Integer num) {PageHelper.startPage(page,num);
//        List<Emp> empList = empMapper.selectEmp();List<Emp> empList = empMapper.selectEmi(name,gender,begin,end);Page<Emp> p = (Page<Emp>) empList;PageBean pageBean = new PageBean(p.getTotal(),p.getResult());return pageBean;}
条件分页查询

使用动态SQL

请求路径/emps

请求方式:GET

<select id="selectEmi" resultType="com.example.tlias.pojo.Emp">select * from emp<where><if test="name != null and name != ''">name like concat('%',#{name},'%')</if><if test="gender != null">and gender = #{gender}</if><if test="begin != null and end != null">and entrydate between #{begin} and #{end}</if></where></select>

删除员工

请求路径:/emps/{ids}

请求方式:DELETE

在路径参数中传递多个id,在后端springboot中对其封装到集合中,在Mybatis中通过动态sql来完成批量删除操作

//控制层@DeleteMapping("/emps/{ids}")Result delete(@PathVariable List<Integer> ids);@Overridepublic Result delete(List<Integer> ids) {empService.delete(ids);return Result.success();}//业务层void delete(List<Integer> id);@Overridepublic void delete(List<Integer> id) {empMapper.delete(id);System.out.println(id);}//持久层void delete(@Param("id") List<Integer> id);
<delete id="delete">delete from emp where id in<foreach collection="id"item = "item"open = "("separator=","close=")">#{item}</foreach></delete>

遍历集合进行sql判断

http://www.yayakq.cn/news/933420/

相关文章:

  • 佛山找人做网站白度指数
  • 旅游景区网站模板华为公司电子商务网站建设策划书
  • 如何用网站做推广成都城乡建设网站
  • iis6.0新发布网站访问速度慢手机百度网址是什么
  • 网站建设个人接单个人 可以做社交网站
  • 电脑小游戏网站自助网站建设工具
  • 上虞做网站公司百度经验首页官网
  • 网站开发包括哪些工作wordpress删除媒体库功能
  • 关于网站建设的好处wordpress禁止右键
  • 网站建设前十名网站做中英版
  • 北京网站建设方案案例有后台的网站模板
  • 网站等保需要几年一做网站下载免费的视频软件
  • wordpress做的网站扩展性小程序和公众号的关系
  • 云南固恒建设集团有限公司网站后台html模板
  • 自助建站程序建立网站英文
  • 公司网站建设应包含哪几个板块网站建设以哪种销售方式好
  • 公司的网站代码运行软件
  • 三亚做民宿的都用什么网站优化大师官网下载安装
  • 河南做网站需要多少钱wordpress授权怎么破解
  • 专业型企业网站有哪些wordpress 预览插件
  • 泰安市景区建设网站网络营销软件条件
  • 网站建设网站需求分析报告功能seo 培训教程
  • 济南城乡建设官方网站wordpress 转 ios app
  • 众鱼深圳网站建设女生做新媒体运营是不是很累
  • 辽宁省网站备案注销东莞建筑
  • 网站公司怎么做的好处做推送网站
  • 网站建设技术课程设计报告化妆品网站 源码
  • 网站开发个人总结厦门海绵城市建设官方网站
  • 高端网站开发地址河南省建设厅资质公示
  • 网站多少钱一年泉州中企动力科技股份有限公司