标签:实现类 select vat pass 删除 his public family let
package com.wn.springbootproject04.entity; import java.io.Serializable; public class Petbreed implements Serializable { private Integer petId; private String petBreed; public Petbreed(Integer petId, String petBreed) { this.petId = petId; this.petBreed = petBreed; } public Petbreed(String petBreed) { this.petBreed = petBreed; } public Petbreed() { } public Integer getPetId() { return petId; } public void setPetId(Integer petId) { this.petId = petId; } public String getPetBreed() { return petBreed; } public void setPetBreed(String petBreed) { this.petBreed = petBreed; } }
#配置数据源 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql:///petmanage spring.datasource.username=root spring.datasource.password=123
#配置端口 server.port=8004
#映射xml文件 mybatis.mapper-locations=classpath:/mapper/*.xml
@Repository public interface PetbreedDao { //查询 public List<Petbreed> getAll(); //新增 public Integer getinsert(Petbreed petbreed); //修改 public Integer getupdate(Petbreed petbreed); //删除 public Integer getdel(@Param("id") Integer id); }
<?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指定Dao接口的完整类名 mybatis会依据这个接口动态创建一个实现类去实现这个接口, 而这个实现类是一个Mapper对象--> <mapper namespace="com.wn.springbootproject04.dao.PetbreedDao"> <resultMap id="MapList" type="com.wn.springbootproject04.entity.Petbreed"> <id property="perId" column="petId"></id> <result property="perBreed" column="petBreed"></result> </resultMap> <!--查询全部--> <select id="getAll" resultType="com.wn.springbootproject04.entity.Petbreed"> SELECT * FROM petbreed </select> <!--新增--> <insert id="getinsert"> INSERT INTO petbreed(petBreed) VALUE(#{petBreed}) </insert> <!--修改--> <update id="getupdate"> UPDATE petbreed SET petBreed=#{petBreed} WHERE petId=#{petId} </update> <!--删除--> <delete id="getdel"> DELETE FROM petbreed WHERE petId=#{id} </delete> </mapper>
public interface PetbreedService { //查询 public List<Petbreed> getAll(); //新增 public Integer getinsert(Petbreed petbreed); //修改 public Integer getupdate(Petbreed petbreed); //删除 public Integer getdel(@Param("id") Integer id); }
@Service("petService") public class PetbreedServiceImpl implements PetbreedService { //植入dao层对象 @Resource private PetbreedDao dao; @Override public List<Petbreed> getAll() { return dao.getAll(); } @Override public Integer getinsert(Petbreed petbreed) { return dao.getinsert(petbreed); } @Override public Integer getupdate(Petbreed petbreed) { return dao.getupdate(petbreed); } @Override public Integer getdel(Integer id) { return dao.getdel(id); } }
@Controller @RequestMapping("/breed") public class PetbreedController { //植入service层对象 @Resource(name = "petService") private PetbreedService service; //查询 @RequestMapping("/getAll") @ResponseBody public List<Petbreed> getAll(){ List<Petbreed> all = service.getAll(); return all; } //新增 @RequestMapping("/getinsert") @ResponseBody public Integer getinsert(){ Integer getinster = service.getinsert(new Petbreed("hhh")); return getinster; } //修改 @RequestMapping("/getupdate") @ResponseBody public Integer getupdate(){ Integer getupdate = service.getupdate(new Petbreed(9, "小猫")); return getupdate; } //删除 @RequestMapping("/getdel") @ResponseBody public Integer getdel(){ Integer getdel = service.getdel(9); return getdel; } }
新增后的数据库,新增了id为11的数据;
修改后的数据库,id为9的数据修改为小猫
删除后的数据库,id为9的数据没有了
标签:实现类 select vat pass 删除 his public family let
原文地址:https://www.cnblogs.com/wnwn/p/12038466.html