黑马程序员技术交流社区

标题: 【郑州校区】传智健康项目讲义第二章四 [打印本页]

作者: 我是楠楠    时间: 2019-10-23 15:54
标题: 【郑州校区】传智健康项目讲义第二章四
本帖最后由 我是楠楠 于 2019-10-23 15:56 编辑

【郑州校区】传智健康项目讲义第二章预约管理-检查项管理四

3.2 后台代码

3.2.1 Controller

health_backend工程中创建CheckItemController

[AppleScript] 纯文本查看 复制代码
package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;

import com.itheima.constant.MessageConstant;

import com.itheima.entity.PageResult;

import com.itheima.entity.QueryPageBean;

import com.itheima.entity.Result;

import com.itheima.pojo.CheckItem;

import com.itheima.service.CheckItemService;

import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**

* 体检检查项管理

*/

@RestController

@RequestMapping("/checkitem")

public class CheckItemController {

@Reference

private CheckItemService checkItemService;

//新增

@RequestMapping("/add")

public Result add(@RequestBody CheckItem checkItem){

try {

checkItemService.add(checkItem);

}catch (Exception e){

return new Result(false,MessageConstant.ADD_CHECKITEM_FAIL);

}

return new Result(true,MessageConstant.ADD_CHECKITEM_SUCCESS);

}

}


3.2.2 服务接口

health_interface工程中创建CheckItemService接口


[AppleScript] 纯文本查看 复制代码
package com.itheima.service;

import com.itheima.pojo.CheckItem;

import java.util.List;

/**

* 检查项服务接口

*/

public interface CheckItemService {

public void add(CheckItem checkItem);

}


3.2.3 服务实现类

health_service_provider工程中创建CheckItemServiceImpl实现类

[AppleScript] 纯文本查看 复制代码
 package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;

import com.itheima.dao.CheckItemDao;

import com.itheima.pojo.CheckItem;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.transaction.annotation.Transactional;

/**

* 检查项服务

*/

@Service(interfaceClass = CheckItemService.class)

@Transactional

public class CheckItemServiceImpl implements CheckItemService {

@Autowired

private CheckItemDao checkItemDao;

//新增

public void add(CheckItem checkItem) {

checkItemDao.add(checkItem);

}

}



3.2.4 Dao接口

health_service_provider工程中创建CheckItemDao接口,本项目是基于MybatisMapper代理技术实现持久层操作,故只需要提供接口和Mapper映射文件,无须提供实现类


[AppleScript] 纯文本查看 复制代码
package com.itheima.dao;

import com.itheima.pojo.CheckItem;

/**

* 持久层Dao接口

*/

public interface CheckItemDao {

public void add(CheckItem checkItem);

}


3.2.5 Mapper映射文件

health_service_provider工程中创建CheckItemDao.xml映射文件,需要和CheckItemDao接口在同一目录下


[AppleScript] 纯文本查看 复制代码
<?xml version="1.0" encoding="UTF‐8" ?>

<!DOCTYPE mapper PUBLIC "‐//mybatis.org//DTD Mapper 3.0//EN"

"http://mybatis.org/dtd/mybatis‐3‐mapper.dtd" >

<mapper namespace="com.itheima.dao.CheckItemDao">

<!‐‐新增‐‐>

<insert id="add" parameterType="com.itheima.pojo.CheckItem">

insert into

t_checkitem(code,name,sex,age,price,type,remark,attention)

values

(#{code},#{name},#{sex},#{age},#{price},#{type},#{remark},#

{attention})

</insert>

</mapper>








欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2