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. uboot下的网络终端/控制台

    许多linux设备可能没有外置串口,这是就需要一个网络终端来在uboot下操作设备,如升级镜像等. uboot下的网络终端为netconsole,代码drivers/net/netconsole.c. ...

  2. android开发(26) 和其他应用交换数据方式一,使用intent指定自定义action调用其他程序里的activity,并获得其返回的结果

    我们在开发中会遇到和其他应用的交互情形,下面是一个简单的方式.整个的使用类似“使用intent调用系统自带的拍照应用并获得结果”. 先看页面:     我们看看实现步骤. 第一个应用 DEMO1: 1 ...

  3. PCL深度图像(1)

    目前深度图像的获取方法有激光雷达深度成像法,计算机立体视觉成像,坐标测量机法,莫尔条纹法,结构光法等等,针对深度图像的研究重点主要集中在以下几个方面,深度图像的分割技术 ,深度图像的边缘检测技术 ,基 ...

  4. 三篇文章了解 TiDB 技术内幕——说存储

    数据库.操作系统和编译器并称为三大系统,可以说是整个计算机软件的基石.其中数据库更靠近应用层,是很多业务的支撑.这一领域经过了几十年的发展,不断的有新的进展. 很多人用过数据库,但是很少有人实现过一个 ...

  5. HashTable和HashMap的区别详解

    一.HashMap简介 HashMap是基于哈希表实现的,每一个元素是一个key-value对,其内部通过单链表解决冲突问题,容量不足(超过了阀值)时,同样会自动增长. HashMap是非线程安全的, ...

  6. php 根据身份证获取出身地址

    <?php /**根据身份证算出地址****/ class addr{ /**获取省***/ public function get_shenfen($id){ //截取前两位数 $index ...

  7. Visual Studio “14” CTP 3 Released

    http://blogs.msdn.com/b/visualstudio/archive/2014/08/18/visual-studio-14-ctp-3-released.aspx Today w ...

  8. C#往SQLServer中插入大数据

    以前插入大数据的时候都是一条一条的插入,由于电脑配置不行,有一次17万条数据用了半个小时才插入完成,那个蛋疼啊! 前面听杨中科老师的课,发现一个很好的东西,25万条数据配置好的电脑几秒钟就完成了,那是 ...

  9. K-SVD算法

    它与K-mean算法原理上是类似的: K-mean 算法: (之前写过:http://www.cnblogs.com/yinheyi/p/6132362.html) 对于初始化的类别中心,可以看作初化 ...

  10. discuz X论坛技术架构 MVC结构浅析

    摘自:http://yeyuan.iteye.com/blog/930727 PS:本人刚接触discuz论坛,php水平有限,当中的理解,如有不正确之处,欢迎指出 ----------------- ...