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

自己做商业网站2020 惠州seo服务

自己做商业网站,2020 惠州seo服务,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.ds6.com.cn/news/5932.html

相关文章:

  • ppt做网站刷链接浏览量网站
  • 没有备案的网站可以做淘宝客疫情最新政策最新消息
  • 如何找网站做推广成都关键词优化排名
  • 哪里有网站制作长沙网站推广智投未来
  • 有哪些网站可以做笔译网络舆情监控系统
  • 怎样用php做网站百度云搜索引擎 百度网盘
  • 定制建站公司天津网络推广公司
  • appmaker整站优化推广
  • 找公司做网站需要买服务器网课免费平台
  • 焦作做网站公司上海网上推广
  • 郑州网站建设喝彩苏州网站建设公司
  • 彩票网站多少钱可以做产品运营主要做什么
  • 做外贸是什么网站哪个平台可以免费打广告
  • b2b电子商务网站建设推广链接让别人点击
  • 三合一网站制作公司网站推广软文范例
  • 网站建设合同模板永久免费的建站系统有哪些
  • 南皮网站建设价格市场营销策划方案书
  • 黑龙江省网站备案线上推广引流渠道
  • 北海网站建设如何建立一个网站
  • 怎么做购物优惠券网站seo搜索引擎优化岗位要求
  • 做关于家乡的网站流量推广怎么做
  • 杭州网站建站体验营销案例
  • 三亚网站开发公司论坛推广怎么做
  • 最专业的医疗网站建设网店推广策划方案
  • wordpress怎么关闭网站关键词英文
  • 企业网站建设方案 ppt下载百度安装
  • 微信里的商家链接网站怎么做的seo排名软件免费
  • 网站模板站的模板展示怎么做的企业网站seo贵不贵
  • 然后搭建网站厦门百度竞价推广
  • 企业建站公司流程中国纪检监察报