<dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <scope>test</scope> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.47</version> </dependency> <dependency> <groupid>org.mybatis.spring.boot</groupid> <artifactid>mybatis-spring-boot-starter</artifactid> <version>1.3.0</version> </dependency> <dependency> <groupid>com.alibaba</groupid> <artifactid>druid-spring-boot-starter</artifactid> <version>1.1.16</version> </dependency> <dependency> <groupid>org.projectlombok</groupid> <artifactid>lombok</artifactid> <version>1.18.10</version> </dependency>
package com.example.mybatis.repository; import com.example.mybatis.domain.smscoupon; import org.apache.ibatis.annotations.param; /** * @author shanks on 2019-11-09 */ public interface smscoupondao { smscoupon querybyid(@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="com.example.mybatis.repository.smscoupondao"> <resultmap type="com.example.mybatis.domain.smscoupon" id="smscouponmap"> <result property="id" column="id" jdbctype="integer"/> <result property="type" column="type" jdbctype="integer"/> <result property="name" column="name" jdbctype="varchar"/> <result property="platform" column="platform" jdbctype="integer"/> <result property="count" column="count" jdbctype="integer"/> <result property="amount" column="amount" jdbctype="numeric"/> <result property="perlimit" column="per_limit" jdbctype="integer"/> <result property="minpoint" column="min_point" jdbctype="numeric"/> <result property="starttime" column="start_time" jdbctype="timestamp"/> <result property="endtime" column="end_time" jdbctype="timestamp"/> <result property="usetype" column="use_type" jdbctype="integer"/> <result property="note" column="note" jdbctype="varchar"/> <result property="publishcount" column="publish_count" jdbctype="integer"/> <result property="usecount" column="use_count" jdbctype="integer"/> <result property="receivecount" column="receive_count" jdbctype="integer"/> <result property="enabletime" column="enable_time" jdbctype="timestamp"/> <result property="code" column="code" jdbctype="varchar"/> <result property="memberlevel" column="member_level" jdbctype="integer"/> </resultmap> <!--查询单个--> <select id="querybyid" resultmap="smscouponmap"> select id, type, name, platform, count, amount, per_limit, min_point, start_time, end_time, use_type, note, publish_count, use_count, receive_count, enable_time, code, member_level from mall.sms_coupon where id = #{id} </select> </mapper>
package com.example.mybatis.config; import org.mybatis.spring.annotation.mapperscan; import org.springframework.context.annotation.configuration; /** * @author shanks on 2019-11-09 */ @configuration @mapperscan("com.example.mybatis.repository") public class mybatisconfig { }
spring: datasource: #数据源基本配置 url: jdbc:mysql://localhost:3306/mall?allowmultiqueries=true&characterencoding=utf-8&usessl=false type: com.alibaba.druid.pool.druiddatasource driver-class-name: com.mysql.jdbc.driver username: root password: 123456 druid: #连接池配置, 初始化大小,最小,最大 initial-size: 5 max-active: 10 #配置获取连接等待超时的时间 max-wait: 60000 #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 time-between-eviction-runs-millis: 60000 #配置一个连接在池中最小生存的时间,单位是毫秒 min-evictable-idle-time-millis: 300000 validation-query: select 1 test-while-idle: true test-on-borrow: false test-on-return: false mybatis: mapper-locations: classpath:mybatis/mapper/*.xml
package com.example.mybatis.web; import com.example.mybatis.domain.smscoupon; import com.example.mybatis.service.smscouponservice; import org.springframework.beans.factory.annotation.autowired; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestparam; import org.springframework.web.bind.annotation.restcontroller; /** * @author shanks on 2019-11-09 */ @restcontroller @requestmapping("/voucher/web/") public class smscouponcontroller { @autowired smscouponservice smscouponservice; @requestmapping("/querysmscoupondetail") public smscoupon querysmscoupondetail(@requestparam("id") int id){ smscoupon smscoupon = smscouponservice.querysmscoupondetail(id); return smscoupon; } }
package com.example.mybatis.service; import com.example.mybatis.domain.smscoupon; /** * @author shanks on 2019-11-09 */ public interface smscouponservice { smscoupon querysmscoupondetail(int id); }
package com.example.mybatis.service.impl; import com.example.mybatis.domain.smscoupon; import com.example.mybatis.repository.smscoupondao; import com.example.mybatis.service.smscouponservice; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.service; /** * @author shanks on 2019-11-09 */ @service public class smscouponserviceimpl implements smscouponservice { @autowired private smscoupondao smscoupondao; @override public smscoupon querysmscoupondetail(int id) { smscoupon smscoupon = smscoupondao.querybyid(id); return smscoupon; } }
package com.example.mybatis; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; @springbootapplication public class demomybatisapplication { public static void main(string[] args) { springapplication.run(demomybatisapplication.class, args); } }
源代码:https://gitee.com/shanksv/springboot-mybatis.git
如对本文有疑问, 点击进行留言回复!!
详解SpringBoot修改启动端口server.port的四种方式
网友评论