gradle配置mysql驱动,springboot gradle mybatis mysql配置(注解)

package com.future.finance;

import org.mybatis.spring.annotation.MapperScan;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication

@MapperScan("com.future.finance.mapper")

public class FinanceApplication {

public static void main(String[] args) {

ConfigurableApplicationContext context = SpringApplication.run(FinanceApplication.class, args);

}

}

package com.future.finance.entity;

import lombok.Getter;

import lombok.Setter;

import java.io.Serializable;

import java.util.Date;

@Getter

@Setter

public class Information implements Serializable {

private static final long serialVersionUID = 1L;

private Long id;

private String content;

private Date publishDate;

}

package com.future.finance.mapper;

import com.future.finance.entity.Information;

import org.apache.ibatis.annotations.Result;

import org.apache.ibatis.annotations.Results;

import org.apache.ibatis.annotations.Select;

import org.springframework.stereotype.Service;

import java.util.List;

@Service

public interface InformationMapper {

@Select("select * from information")

@Results({

@Result(property = "content", column = "content"),

@Result(property = "publishDate", column = "publish_date")

})

List getAll();

}

package com.future.finance.controller;

import com.future.finance.entity.Information;

import com.future.finance.mapper.InformationMapper;

import com.google.gson.Gson;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController

public class InformationController {

@Autowired

private InformationMapper informationMapper;

private Gson gson = new Gson();

@RequestMapping("/getAll")

public String getAll() {

List result = informationMapper.getAll();

return gson.toJson(result);

}

}

application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/finance?characterEncoding=utf-8&allowMultiQueries=true&serverTimezone=GMT%2B8

spring.datasource.username=jack

spring.datasource.password=jack123456

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false

build.gradle

plugins {

id 'org.springframework.boot' version '2.3.4.RELEASE'

id 'io.spring.dependency-management' version '1.0.10.RELEASE'

id 'java'

}

group = 'com.future'

version = '0.0.1-SNAPSHOT'

sourceCompatibility = '1.8'

repositories {

mavenCentral()

}

dependencies {

// 1. Use Guava in your implementation only:

implementation 'com.google.guava:guava:29.0-jre'

implementation 'com.google.code.gson:gson:2.8.5'

compile("org.springframework.boot:spring-boot-devtools") // 热部署

compileOnly 'org.projectlombok:lombok:1.18.12'

implementation 'org.springframework.boot:spring-boot-starter-web'

implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.3'

runtimeOnly 'mysql:mysql-connector-java:8.0.17'

testImplementation('org.springframework.boot:spring-boot-starter-test') {

exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'

}

}

test {

useJUnitPlatform()

}

// debug

//bootRun {

// jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"

//}

然后postman访问

localhost:8080/getAll

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值