mirror of
https://github.com/JeffLi1993/springboot-learning-example.git
synced 2026-03-14 06:03:52 +08:00
Springboot 实现 Restful 服务,基于 HTTP / JSON 传输
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
## 数据源配置
|
||||
spring.datasource.url=jdbc:mysql://139.224.14.39:3306/springbootdb?useUnicode=true&characterEncoding=utf8
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=Hello123!@
|
||||
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||
|
||||
## Mybatis 配置
|
||||
mybatis.typeAliasesPackage=org.spring.springboot.domain
|
||||
mybatis.mapperLocations=classpath:mapper/*.xml
|
||||
60
springboot-restful/src/main/resources/mapper/CityMapper.xml
Normal file
60
springboot-restful/src/main/resources/mapper/CityMapper.xml
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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="org.spring.springboot.dao.CityDao">
|
||||
<resultMap id="BaseResultMap" type="org.spring.springboot.domain.City">
|
||||
<result column="id" property="id" />
|
||||
<result column="province_id" property="provinceId" />
|
||||
<result column="city_name" property="cityName" />
|
||||
<result column="description" property="description" />
|
||||
</resultMap>
|
||||
|
||||
<parameterMap id="City" type="org.spring.springboot.domain.City"/>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id, province_id, city_name, description
|
||||
</sql>
|
||||
|
||||
<select id="findById" resultMap="BaseResultMap" parameterType="java.lang.Long">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from city
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="findAllCity" resultMap="BaseResultMap" >
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from city
|
||||
</select>
|
||||
|
||||
<insert id="saveCity" parameterMap="City" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into
|
||||
city(id,province_id,city_name,description)
|
||||
values
|
||||
(#{id},#{provinceId},#{cityName},#{description})
|
||||
</insert>
|
||||
|
||||
<update id="updateCity" parameterMap="City">
|
||||
update
|
||||
city
|
||||
set
|
||||
<if test="provinceId!=null">
|
||||
province_id = #{provinceId},
|
||||
</if>
|
||||
<if test="cityName!=null">
|
||||
city_name = #{cityName},
|
||||
</if>
|
||||
<if test="description!=null">
|
||||
description = #{description}
|
||||
</if>
|
||||
where
|
||||
id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteCity" parameterType="java.lang.Long">
|
||||
delete from
|
||||
city
|
||||
where
|
||||
id = #{id}
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user