idea--springboot的增删改查的代码以及配置文件之代码(实体类,mapper文件,service和control,启动类)
  cCuitpmOqlQw 2023年11月02日 62 0


实体类:

package com.zdc.entity;

public class GgCzyb {
private String id;
private String mc;
private String dlh;
private String name;
private String phone;
private String email;
private Integer type;

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getMc() {
return mc;
}
public void setMc(String mc) {
this.mc = mc;
}
public String getDlh() {
return dlh;
}
public void setDlh(String dlh) {
this.dlh = dlh;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
}

mapper接口

package com.zdc.mapper;

import com.zdc.entity.GgCzyb;

import java.util.List;

public interface GgCzybMapper {

int create(GgCzyb ggCzyb);

int delete(String ggCzybId);

int update(GgCzyb ggCzyb);

List<GgCzyb> query(GgCzyb ggCzyb);

GgCzyb detail(String ggCzybId);

}

mapper.xml文件(增删改查sql片段等)

<?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.zdc.mapper.GgCzybMapper">

<resultMap id="ggczyb" type="com.zdc.entity.GgCzyb">
<id column="id" property="id"></id>
<result column="mc" property="mc"></result>
<result column="dlh" property="dlh"></result>
<result column="name" property="name"></result>
<result column="phone" property="phone"></result>
<result column="email" property="email"></result>
<result column="type" property="type"></result>
</resultMap>

<insert id="create" keyProperty="id" useGeneratedKeys="true" parameterType="com.zdc.entity.GgCzyb">
insert into gg_czyb(id,mc,dlh,name,phone,email,type)
values (#{id},#{mc},#{dlh},#{name},#{phone},#{email},#{type})
</insert>

<delete id="delete">
delete from gg_czyb where id = #{id}
</delete>

<update id="update" parameterType="com.zdc.entity.GgCzyb">
update gg_czyb set mc = #{mc},dlh = #{dlh},name = #{name},phone = #{phone},email = #{email},type = #{type}
where id = #{id}
</update>

<select id="query" resultMap="ggczyb">
select * from gg_czyb
<include refid="WhereGgczyb"></include>
</select>

<sql id="WhereGgczyb">
<where>
<if test="id != null"> and id = #{id}</if>
<if test="mc != null and mc != ''"> and mc = #{mc}</if>
</where>
</sql>

<select id="detail" resultMap="ggczyb">
select * from gg_czyb where id = #{id}
</select>

</mapper>

service文件

package com.zdc.service;

import com.zdc.entity.GgCzyb;
import com.zdc.mapper.GgCzybMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GgCzybService {

@Autowired
private GgCzybMapper ggCzybMapper;

public int create(GgCzyb ggCzyb){
return ggCzybMapper.create(ggCzyb);
}

public int delete(String ggCzybId){
return ggCzybMapper.delete(ggCzybId);
}

public int update(GgCzyb ggCzyb){
return ggCzybMapper.update(ggCzyb);
}

public List<GgCzyb> query(GgCzyb ggCzyb){
return ggCzybMapper.query(ggCzyb);
}

public GgCzyb detail(String ggCzybId){
return ggCzybMapper.detail(ggCzybId);
}

}

control文件:

package com.zdc.controller;

import com.zdc.entity.GgCzyb;
import com.zdc.service.GgCzybService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ggCzyb")
public class GgCzybController {

@Autowired
private GgCzybService ggCzybService;

@GetMapping("create")
public void create(){
GgCzyb ggCzyb = new GgCzyb();
// ggCzyb.setId("00001");
ggCzyb.setId("00002");
// ggCzyb.setId("00003");
ggCzyb.setMc("zdc");
ggCzyb.setDlh("0");
ggCzyb.setName("ZDC");
ggCzyb.setPhone("15886798332");
ggCzyb.setEmail("1425071636@qq.com");
ggCzyb.setType(1);
ggCzybService.create(ggCzyb);
}

@GetMapping("delete")
public void delete(String ggCzybId){
ggCzybService.delete(ggCzybId);
}

@GetMapping("update")
public void update(){
GgCzyb ggCzyb = new GgCzyb();
ggCzyb.setId("00001");
ggCzyb.setMc("zdc11");
ggCzyb.setDlh("011");
ggCzyb.setName("ZDC11");
ggCzyb.setPhone("1588679833211");
ggCzyb.setEmail("1425071636@qq.com11");
ggCzyb.setType(2);
ggCzybService.update(ggCzyb);
}

@GetMapping("query")
public List<GgCzyb> query(GgCzyb ggCzyb){
return ggCzybService.query(ggCzyb);
}

@GetMapping("detail")
public GgCzyb detail(String ggCzybId){
return ggCzybService.detail(ggCzybId);
}
}

启动类:

package com.zdc;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan({"com.zdc.mapper"})
public class ShowtimeApplication {

public static void main(String[] args) {
SpringApplication.run(ShowtimeApplication.class, args);
}

}


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  Fv5flEkOgYS5   2023年11月02日   51   0   0 i++javaide
cCuitpmOqlQw