用IntelliJ的IDEA来创建SpringBoot框架

要安装ULTIMATE版本,并导入key

http://idea.iteblog.com/key.php

安装完成后

1:首先打开New Project
2:选择Spring Initializr  这里直接按Next
3:配置Metadata
Group:com.example
Arifact:demo|
这里直接按Next
4:勾选Web、MyBatis、MySQL然后Next

 

编辑文件application.properties,添加服务端口、数据库配置

server.port=8081
server.address=0.0.0.0

spring.datasource.url=jdbc:mysql://mysql.feieryun.cn/firadio_yun?verifyServerCertificate=false&useSSL=false
spring.datasource.username=feieryun
spring.datasource.password=feieryun

 

在DemoApplication.java的同级文件夹
也就是在\demo\src\main\java\com\example\demo下面
新建文件夹controller,然后在里面新建IndexController.java

package com.feieryun.ssproxy.controller;

import com.feieryun.ssproxy.model.bootstrapt.BaseResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {
    @RequestMapping(value = {"/"}, method = RequestMethod.GET)
    public BaseResult index() {
        return new BaseResult(false, "Hello World!", false);
    }
}

 


这个是BaseResult

package com.feieryun.ssproxy.model.bootstrapt;

import java.io.Serializable;

/**
 */
public class BaseResult implements Serializable {

    //private static final long serialVersionUID = -5231857415211397573L;
    private boolean success;
    private String msg;
    private Object data;

    public BaseResult() {
    }

    public BaseResult(boolean success, String msg, Object data) {
        this.success = success;
        this.msg = msg;
        this.data = data;
    }


    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}

 

 

这里是DatabaseConfig的内容

package com.example.demo;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;

import javax.sql.DataSource;

@Configuration
@EnableTransactionManagement
@MapperScan(basePackages = "com.example.demo.mapper")
public class DatabaseConfig implements TransactionManagementConfigurer {

    @Autowired
    DataSource dataSource;

    @Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
        sqlSessionFactory.setDataSource(dataSource);
        sqlSessionFactory.setFailFast(true);
        return sqlSessionFactory.getObject();
    }

    @Bean
    public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
        return new SqlSessionTemplate(sqlSessionFactory);
    }

    /**
     * @fun 配置事务管理器
     */
    @Bean
    @Override
    public PlatformTransactionManager annotationDrivenTransactionManager() {
        return new DataSourceTransactionManager(dataSource);
    }

}

 

转载于:https://www.cnblogs.com/xiangxisheng/p/7850460.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值