Skip to content

Commit

Permalink
#
Browse files Browse the repository at this point in the history
  • Loading branch information
Relucent committed Aug 13, 2020
1 parent 4d49c7d commit 62b224f
Show file tree
Hide file tree
Showing 21 changed files with 930 additions and 928 deletions.
51 changes: 51 additions & 0 deletions spring-boot-example-mybatis-extends/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Compile files
*.class

# Package Files
*.jar
*.war
*.ear
*.nar
*.zip
*.tar
*.tar.gz
*.rar

# Maven
target/
*.ser
*.ec

# J2ME
.mtj.tmp/

# Eclipse
.classpath
.project
.settings/
.metadata/
.factorypath
.springBeans

# IntelliJ Idea
.idea/
out/
*.ipr
*.iws
*.iml

# BlueJ Files
*.ctxt

# OS X
.DS_Store

# Window
Thumbs.db

# Virtual Machine Crash Logs
hs_err_pid*

# Log File
*.log
*.log.*
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
package yyl.springboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import yyl.springboot.entity.Hello;
import yyl.springboot.mapper.HelloMapper;

@RestController
@RequestMapping("/hello")
public class HelloController {

@Autowired
private HelloMapper helloMapper;

// | /hello/
@GetMapping("/")
public Object findAll() {
return helloMapper.findAll();
}

// | /hello/{id}
@GetMapping("/{id}")
public Object getById(@PathVariable Long id) {
return helloMapper.getById(id);
}

// | /hello/
@PostMapping("/")
public Object save(@RequestBody Hello model) {
Long id = model.getId();
if (id == null) {
helloMapper.insert(model);
} else {
helloMapper.update(model);
}
return Boolean.TRUE;
}

// | /hello/{id}
@PutMapping(value = "/{id}")
public Object update(@PathVariable Long id, @RequestBody Hello model) {
model.setId(id);
helloMapper.update(model);
return Boolean.TRUE;
}

// | /hello/{id}
@DeleteMapping(value = "/{id}")
public void delete(@PathVariable("id") Long id) {
helloMapper.deleteById(id);
}

package yyl.springboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import yyl.springboot.entity.Hello;
import yyl.springboot.mapper.HelloMapper;

@RestController
@RequestMapping("/hello")
public class HelloController {

@Autowired
private HelloMapper helloMapper;

// | /hello/
@PostMapping("/")
public Object save(@RequestBody Hello model) {
Long id = model.getId();
if (id == null) {
helloMapper.insert(model);
} else {
helloMapper.updateById(model);
}
return Boolean.TRUE;
}

// | /hello/{id}
@DeleteMapping(value = "/{id}")
public void delete(@PathVariable("id") Long id) {
helloMapper.deleteById(id);
}

// | /hello/{id}
@PutMapping(value = "/{id}")
public Object update(@PathVariable Long id, @RequestBody Hello model) {
model.setId(id);
helloMapper.updateById(model);
return Boolean.TRUE;
}

// | /hello/{id}
@GetMapping("/{id}")
public Object getById(@PathVariable Long id) {
return helloMapper.selectById(id);
}

// | /hello/
@GetMapping("/")
public Object list() {
return helloMapper.selectAllList();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package yyl.springboot.mapper.basic;

import java.util.List;

import yyl.springboot.entity.Hello;

public interface HelloBasicMapper {

List<Hello> findAll();

Hello getById(Long id);

void insert(Hello hello);

void update(Hello hello);

void deleteById(Long id);

package yyl.springboot.mapper.basic;

import java.util.List;

import yyl.springboot.entity.Hello;

public interface HelloBasicMapper {

void insert(Hello hello);

void deleteById(Long id);

void updateById(Hello hello);

Hello selectById(Long id);

List<Hello> selectAllList();
}
Original file line number Diff line number Diff line change
@@ -1,62 +1,53 @@
<?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="yyl.springboot.mapper.basic.HelloBasicMapper">

<resultMap id="RESULT_MAP" type="yyl.springboot.entity.Hello">
<id column="id" property="id" jdbcType="BIGINT" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="value" property="value" jdbcType="VARCHAR" />
</resultMap>

<sql id="TABLE">hello</sql>

<sql id="COLUMNS">
id, name, value
</sql>

<select id="findAll" resultMap="RESULT_MAP">
SELECT
<include refid="COLUMNS" />
FROM
<include refid="TABLE" />
</select>

<select id="getById" parameterType="java.lang.Long" resultMap="RESULT_MAP">
SELECT
<include refid="COLUMNS" />
FROM
<include refid="TABLE" />
WHERE id = #{id}
</select>

<insert id="insert" parameterType="yyl.springboot.entity.Hello">
INSERT INTO
<include refid="TABLE" />
(name,value)
VALUES
(#{name}, #{value})
</insert>

<update id="update" parameterType="yyl.springboot.entity.Hello">
UPDATE
<include refid="TABLE" />
<set>
<if test="name != null">
name = #{name},
</if>
<if test="value != null">
value = #{value},
</if>
</set>
WHERE
id = #{id}
</update>

<delete id="deleteById" parameterType="java.lang.Long">
DELETE FROM
<include refid="TABLE" />
WHERE
id =#{id}
</delete>

<?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="yyl.springboot.mapper.basic.HelloBasicMapper">
<resultMap id="RESULT_MAP" type="yyl.springboot.entity.Hello">
<id column="id" property="id" jdbcType="BIGINT" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="value" property="value" jdbcType="VARCHAR" />
</resultMap>
<sql id="TABLE">hello</sql>
<sql id="COLUMNS">
id, name, value
</sql>
<insert id="insert" parameterType="yyl.springboot.entity.Hello">
INSERT INTO
<include refid="TABLE" />
(name,value)
VALUES
(#{name}, #{value})
</insert>
<delete id="deleteById" parameterType="java.lang.Long">
DELETE FROM
<include refid="TABLE" />
WHERE
id =#{id}
</delete>
<update id="updateById" parameterType="yyl.springboot.entity.Hello">
UPDATE
<include refid="TABLE" />
<set>
<if test="name != null">
name = #{name},
</if>
<if test="value != null">
value = #{value},
</if>
</set>
WHERE
id = #{id}
</update>
<select id="selectById" parameterType="java.lang.Long" resultMap="RESULT_MAP">
SELECT
<include refid="COLUMNS" />
FROM
<include refid="TABLE" />
WHERE id = #{id}
</select>
<select id="selectAllList" resultMap="RESULT_MAP">
SELECT
<include refid="COLUMNS" />
FROM
<include refid="TABLE" />
</select>
</mapper>
Loading

0 comments on commit 62b224f

Please sign in to comment.