Skip to content

Commit

Permalink
add mybatis2
Browse files Browse the repository at this point in the history
  • Loading branch information
527515025 committed Apr 2, 2019
1 parent bbe8e37 commit d413685
Show file tree
Hide file tree
Showing 15 changed files with 643 additions and 0 deletions.
57 changes: 57 additions & 0 deletions springboot-mybatis2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>cn.abel</groupId>
<artifactId>springboot-mybatis2</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/>
</parent>

<dependencies>
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
</dependencies>

</project>
16 changes: 16 additions & 0 deletions springboot-mybatis2/src/main/java/cn/abel/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cn.abel;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author yyb
* @time 2019/3/26
*/
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}
50 changes: 50 additions & 0 deletions springboot-mybatis2/src/main/java/cn/abel/bean/News.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cn.abel.bean;


public class News {
private Integer id;
private String title;
private String content;
private String imagePath;
private Integer readSum;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getImagePath() {
return imagePath;
}

public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}

public Integer getReadSum() {
return readSum;
}

public void setReadSum(Integer readSum) {
this.readSum = readSum;
}
}
70 changes: 70 additions & 0 deletions springboot-mybatis2/src/main/java/cn/abel/bean/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cn.abel.bean;

import java.util.Date;


public class User {
private Integer id;
private String name;
private String address;
private String mobile;
private String email;
private Date createTime;
private Integer role;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getMobile() {
return mobile;
}

public void setMobile(String mobile) {
this.mobile = mobile;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public Date getCreateTime() {
return createTime;
}

public void setCreateTime(Date createTime) {
this.createTime = createTime;
}

public Integer getRole() {
return role;
}

public void setRole(Integer role) {
this.role = role;
}
}
23 changes: 23 additions & 0 deletions springboot-mybatis2/src/main/java/cn/abel/dao/NewsDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cn.abel.dao;

import java.util.List;
import java.util.Map;

import cn.abel.bean.News;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface NewsDao {

List<News> getByMap(Map<String, Object> map);

News getById(Integer id);

Integer create(News news);

int update(News news);

int delete(Integer id);
}
23 changes: 23 additions & 0 deletions springboot-mybatis2/src/main/java/cn/abel/dao/UserDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cn.abel.dao;

import java.util.List;
import java.util.Map;

import cn.abel.bean.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface UserDao {

List<User> getByMap(Map<String, Object> map);

User getById(Integer id);

Integer create(User user);

int update(User user);

int delete(Integer id);
}
40 changes: 40 additions & 0 deletions springboot-mybatis2/src/main/java/cn/abel/service/NewsService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cn.abel.service;

import java.util.List;
import java.util.Map;


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

import cn.abel.dao.NewsDao;
import cn.abel.bean.News;

@Service
public class NewsService {
@Autowired
private NewsDao newsDao;

public List<News> getByMap(Map<String, Object> map) {
return newsDao.getByMap(map);
}

public News getById(Integer id) {
return newsDao.getById(id);
}

public News create(News news) {
newsDao.create(news);
return news;
}

public News update(News news) {
newsDao.update(news);
return news;
}

public int delete(Integer id) {
return newsDao.delete(id);
}

}
39 changes: 39 additions & 0 deletions springboot-mybatis2/src/main/java/cn/abel/service/UserService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cn.abel.service;

import java.util.List;
import java.util.Map;

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

import cn.abel.dao.UserDao;
import cn.abel.bean.User;

@Service
public class UserService {
@Autowired
private UserDao userDao;

public List<User> getByMap(Map<String,Object> map){
return userDao.getByMap(map);
}

public User getById(Integer id){
return userDao.getById(id);
}

public User create(User user){
userDao.create(user);
return user;
}

public User update(User user){
userDao.update(user);
return user;
}

public int delete(Integer id){
return userDao.delete(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
## tomcat\u914D\u7F6E
server.port=8009
#server.tomcat.maxHttpHeaderSize=8192
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.risk.encoding=UTF-8
# tomcat\u6700\u5927\u7EBF\u7A0B\u6570\uFF0C\u9ED8\u8BA4\u4E3A200
server.tomcat.max-threads=800
# session\u6700\u5927\u8D85\u65F6\u65F6\u95F4(\u5206\u949F)\uFF0C\u9ED8\u8BA4\u4E3A30
server.session-timeout=60

## spring \u914D\u7F6E
spring.application.name=springboot-dynamicDataSource
application.main=cn.abel.Application

## LOG
logging.file=./logs/springboot-dynamicDataSource.log


## \u4E3B\u6570\u636E\u6E90\uFF0C\u9ED8\u8BA4\u7684
spring.datasource.url=jdbc:mysql://localhost:3306/oldMan?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=admin
spring.datasource.driverClassName=com.mysql.jdbc.Driver

spring.datasource.type=com.zaxxer.hikari.HikariDataSource
#\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5
spring.datasource.min-idle=5
#\u6700\u5927\u8FDE\u63A5\u6570\u91CF
spring.datasource.max-active=100
#\u68C0\u6D4B\u6570\u636E\u5E93\u7684\u67E5\u8BE2\u8BED\u53E5
spring.datasource.validation-query=select 1 from dual
#\u7B49\u5F85\u8FDE\u63A5\u6C60\u5206\u914D\u8FDE\u63A5\u7684\u6700\u5927\u65F6\u957F\uFF08\u6BEB\u79D2\uFF09
spring.datasource.connection-timeout=60000
#\u4E00\u4E2A\u8FDE\u63A5\u7684\u751F\u547D\u65F6\u957F\uFF08\u6BEB\u79D2\uFF09
spring.datasource.max-left-time=60000
#\u751F\u6548\u8D85\u65F6
spring.datasource.validation-time-out=3000
#\u4E00\u4E2A\u8FDE\u63A5idle\u72B6\u6001\u7684\u6700\u5927\u65F6\u957F\uFF08\u6BEB\u79D2\uFF09
spring.datasource.idle-time-out=60000
#\u8BBE\u7F6E\u9ED8\u8BA4\u5B57\u7B26\u96C6
spring.datasource.connection-init-sql= set names utf8mb4

logging.level.cn.abel.dao=debug
#Mapper.xml\u6240\u5728\u7684\u4F4D\u7F6E
mybatis.mapper-locations=classpath*:mapper/*Mapper.xml
smybatis.type-aliases-package=cn.abel.bean
#Mapper.xml\u6240\u5728\u7684\u4F4D\u7F6E

## pagehelper
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql


5 changes: 5 additions & 0 deletions springboot-mybatis2/src/main/resources/local/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
########################################################
# #
# local #
# #
########################################################
Loading

0 comments on commit d413685

Please sign in to comment.