-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
930 additions
and
928 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.* |
119 changes: 59 additions & 60 deletions
119
...boot-example-mybatis-extends/src/main/java/yyl/springboot/controller/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
35 changes: 17 additions & 18 deletions
35
...t-example-mybatis-extends/src/main/java/yyl/springboot/mapper/basic/HelloBasicMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
113 changes: 52 additions & 61 deletions
113
...boot-example-mybatis-extends/src/main/resources/mybatis/mapper/basic/HelloBasicMapper.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.