spring+mybatise注解实现

 spring.jpa.database=MYSQL

 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=zhangxf123 spring.jpa.show-sql = true spring.datasource.druid.initialSize=5
spring.datasource.druid.minIdle=5
spring.datasource.druid.maxActive=20
spring.datasource.druid.maxWait=60000 spring.datasource.druid.timeBetweenEvictionRunsMillis=60000 spring.datasource.druid.minEvictableIdleTimeMillis=300000 spring.datasource.druid.testWhileIdle=true
spring.datasource.druid.testOnBorrow=true
spring.datasource.druid.testOnReturn=false spring.datasource.druid.poolPreparedStatements=true
spring.datasource.druid.maxPoolPreparedStatementPerConnectionSize=20 spring.datasource.druid.filters=stat,wall,log4j spring.datasource.druid.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
 <?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="/home/zhangxiongfeng/logs" />
<property name="LOG_NAME" value="QSurvey" />
  <!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
  <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
  <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
  </encoder>
</appender>
  <!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  <!--日志文件输出的文件名-->
  <FileNamePattern>${LOG_HOME}/${LOG_NAME}.log.%d{yyyy-MM-dd}.log</FileNamePattern>
  <!--日志文件保留天数-->  
  <MaxHistory>30</MaxHistory>
  </rollingPolicy>
  <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
  <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
  </encoder>
  <!--日志文件最大的大小-->
  <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
  <MaxFileSize>10MB</MaxFileSize>
  </triggeringPolicy>
</appender> <!-- 日志输出级别 -->
  <root level="INFO">
   <appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
  </root>
</configuration>

logback.xml

 package com.newtouch.mybatise;

 import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication
@EnableTransactionManagement
public class MybatiseApplication { public static void main(String[] args) {
SpringApplication.run(MybatiseApplication.class, args);
}
}

MybatiseApplication.java

package com.newtouch.mybatise.controller;

import java.util.HashMap;
import java.util.Map; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import com.newtouch.mybatise.dao.bean.Student;
import com.newtouch.mybatise.service.IStudentService; @RestController
@RequestMapping("/student")
public class StudentController { @Autowired
private IStudentService iStudentService; @RequestMapping("/add")
public Map<String, Object> addStudent(){
Student student = new Student();
student.setName("张雄峰");
student.setAge(34);
iStudentService.addStudent(student);
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("chengong", 1);
return resultMap;
}
}
 package com.newtouch.mybatise.service.impl;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import com.newtouch.mybatise.dao.IStudentDao;
import com.newtouch.mybatise.dao.bean.Student;
import com.newtouch.mybatise.service.IStudentService; @Service
public class StudentServiceImpl implements IStudentService{ @Autowired
private IStudentDao iStudentDao; public void addStudent(Student student){
iStudentDao.addStudent(student);
} }

StudentServiceImpl.java

 package com.newtouch.mybatise.dao.impl;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; import com.newtouch.mybatise.dao.IStudentDao;
import com.newtouch.mybatise.dao.bean.Student;
import com.newtouch.mybatise.dao.mapper.IStudentMapper; @Repository
public class StudentDaoImpl implements IStudentDao { @Autowired
private IStudentMapper iStudentMapper; public void addStudent(Student student){
iStudentMapper.insert(student);
} }

StudentDaoImpl.java

 package com.newtouch.mybatise.dao.bean;

 /**
*
* @author zhangxiongfeng
*
*/
public class Student { private int id;
private String name;
private int age; public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
} }

Student.javas

package com.newtouch.mybatise.dao.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;

import com.newtouch.mybatise.dao.bean.Student;

@Mapper
public interface IStudentMapper {

@Insert("insert into student(name,age) values(#{name},#{age})")
@Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
void insert(Student Student);
}

springboot mybatise 注解实现最主要的类

spring+mybatise注解实现的更多相关文章

  1. Spring MVC注解的一些案列

    1.  spring MVC-annotation(注解)的配置文件ApplicationContext.xml <?xml version="1.0" encoding=& ...

  2. Spring系列之Spring常用注解总结

    传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...

  3. spring @condition 注解

    spring @condition注解是用来在不同条件下注入不同实现的 demo如下: package com.foreveross.service.weixin.test.condition; im ...

  4. spring mvc(注解)上传文件的简单例子

    spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationConte ...

  5. Spring的注解方式实现AOP

    Spring对AOP的实现提供了很好的支持.下面我们就使用Spring的注解来完成AOP做一个例子. 首先,为了使用Spring的AOP注解功能,必须导入如下几个包.aspectjrt.jar,asp ...

  6. Spring 之注解事务 @Transactional

    众所周知的ACID属性:  原子性(atomicity).一致性(consistency).隔离性(isolation)以及持久性(durability).我们无法控制一致性.原子性以及持久性,但可以 ...

  7. 数据库事务中的隔离级别和锁+spring Transactional注解

    数据库事务中的隔离级别和锁 数据库事务在后端开发中占非常重要的地位,如何确保数据读取的正确性.安全性也是我们需要研究的问题.ACID首先总结一下数据库事务正确执行的四个要素(ACID): 原子性(At ...

  8. Spring JSR-250注解

    Java EE5中引入了“Java平台的公共注解(Common Annotations for the Java Platform)”,而且该公共注解从Java SE 6一开始就被包含其中. 2006 ...

  9. 【SSM 2】spring常用注解

    声明:以下观点,纯依据个人目前的经验和理解,有不当之处,多指教! 一.基本概述 注解(Annotation):也叫元数据.一种代码级别的说明.它是JDK1.5及以后版本引入的一个特性,与类.接口.枚举 ...

随机推荐

  1. metrics 开发监控实现jdbc

    Metrics 主要有五大基本组件1:Counter  记录执行次数2:Gauge  获取某个值3:Meter  用来计算事件的速率4:Histogram  可以为数据流提供统计数据. 除了最大值,最 ...

  2. 找回IntelliJ IDEA中 丢失的Run Dashboard 视图

    一般有时候创建springboot项目的时候右下角可以提示你打开Run Dashboard,但是如果不提醒就需要自己配置了. 找到项目中.idea文件下的workspace.xml开打 接下来找到 & ...

  3. Centos7下安装运行keepalived

    master服务器ip地址:192.168.0.182 slave服务器ip地址:192.168.0.189 虚拟ip(VIP,一个尚未占用的内网ip即可)地址:192.168.0.180  确认使用 ...

  4. Android开发 sharesdk分享微信/朋友圈的时候只显示文字,不显示链接

    问题:分享的时候只将分享的content分享出去了,连标题及链接都没有分享出去. 原因:没有配置image导致. 解决办法: 在  showShare 方法里面添加配置: if(ImageUrlOrP ...

  5. Android Studio apk 打包

    1.Build -> Generate Signed APK...,打开如下窗口 2.假设这里没有打过apk包,点击Create new,窗口如下 这里只要输入几个必要项 Key store p ...

  6. USB学习笔记连载(十五):USB固件更新以及安装驱动

    前几篇博客已经把如何更改固件程序和更改USB驱动名称,那么接下来就要把之前生成的 .iic 文件烧录到EEPROM里面去,实现USB的C2启动(笔者使用的是此类型,C2启动). 打开Cypress U ...

  7. 关于Unity中的光照(五)

    Mobile Diffuse Unity自带的一种shader,用的比较多,性能还可以.我们默认创建的unit shader基本和它一致,但是没有参与光照计算,看起来和Mobile Diffuse有区 ...

  8. Python之进度条

    pip install tqdm from tqdm import tqdm,trange import time for char in tqdm(['a','b','c','d']): time. ...

  9. JUnit注解

    在本节中,我们将提到支持在JUnit4基本注释,下表列出了这些注释的概括: 注解 描述 @Testpublic void method() 测试注释指示该公共无效方法它所附着可以作为一个测试用例. @ ...

  10. 使用mysqldiff生成两个数据库结构不同的脚本

    1,全库比较各个表的不同,并输出到文件 mysqldiff --server1=root:root@localhost --server2=root:root@localhost --difftype ...