spring+mybatise注解实现
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注解实现的更多相关文章
- Spring MVC注解的一些案列
1. spring MVC-annotation(注解)的配置文件ApplicationContext.xml <?xml version="1.0" encoding=& ...
- Spring系列之Spring常用注解总结
传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...
- spring @condition 注解
spring @condition注解是用来在不同条件下注入不同实现的 demo如下: package com.foreveross.service.weixin.test.condition; im ...
- spring mvc(注解)上传文件的简单例子
spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationConte ...
- Spring的注解方式实现AOP
Spring对AOP的实现提供了很好的支持.下面我们就使用Spring的注解来完成AOP做一个例子. 首先,为了使用Spring的AOP注解功能,必须导入如下几个包.aspectjrt.jar,asp ...
- Spring 之注解事务 @Transactional
众所周知的ACID属性: 原子性(atomicity).一致性(consistency).隔离性(isolation)以及持久性(durability).我们无法控制一致性.原子性以及持久性,但可以 ...
- 数据库事务中的隔离级别和锁+spring Transactional注解
数据库事务中的隔离级别和锁 数据库事务在后端开发中占非常重要的地位,如何确保数据读取的正确性.安全性也是我们需要研究的问题.ACID首先总结一下数据库事务正确执行的四个要素(ACID): 原子性(At ...
- Spring JSR-250注解
Java EE5中引入了“Java平台的公共注解(Common Annotations for the Java Platform)”,而且该公共注解从Java SE 6一开始就被包含其中. 2006 ...
- 【SSM 2】spring常用注解
声明:以下观点,纯依据个人目前的经验和理解,有不当之处,多指教! 一.基本概述 注解(Annotation):也叫元数据.一种代码级别的说明.它是JDK1.5及以后版本引入的一个特性,与类.接口.枚举 ...
随机推荐
- DLL接口的实现(虚函数)
DLL接口的实现(虚函数) 我们在c++编程过程中往往要用到各种不同形式的程序库,这些库的发布方式有动态库和静态库.对于静态类库,设计良好的静态类库能实现功能上的隔离,无法避免类库实现必须重新编译.链 ...
- Hbase 学习(十一)使用hive往hbase当中导入数据
我们可以有很多方式可以把数据导入到hbase当中,比如说用map-reduce,使用TableOutputFormat这个类,但是这种方式不是最优的方式. Bulk的方式直接生成HFiles,写入到文 ...
- [数学-构造矩阵]NEFU 1113
依据题意.我已经推导出tn的公式.ti=ti.a+ti.b,ti.a=5*t(i-1).a+4*t(i-1).b,ti.b=t(i-1).a+t(i-1).b 然而以下居然不能继续推到sn的公式!!! ...
- android开发(34) 自定义 listView的分割线( 使用xml drawable画多条线)
我遇到这样一个场景,我需要自定义 listView的分割线,而这个分割线是由两条线组成的,在使用xml drawable时遇到了困难. 注释:画两条线是为了实现 凹陷的效果,在绘图中一条暗线紧跟着一条 ...
- this inspection reports usage of the default file template for file header
使用idea创建一个java class的时候会出现如下的warning: this inspection reports usage of the default file template for ...
- Qt中QString、QByteArray、int、double之间转换
最近写Qt中的tcp网络编程,Socke连接后,接受到的数据类型是字节型,这就涉及到了大量的类型转换,在网上辗转几辄,总算有了点结果,特此跟大家分享.好了,不废话,下面细说. 方法/步骤 1. ...
- 访问网站出现EOF
HTTP/0.0 503 Service Unavailable Date: Tuesday, 18-Apr-17 10:29:46 CST Keep-Alive: timeout=38 EOF 今天 ...
- JUnit4参数化测试实例
在JUnit中,可以同时使用@RunWith 和 @parameter 注解来为单元测试传递参数. 注意: 在Eclipse中因为版本问题,可能无法使用@parameters(name = " ...
- Spring JDBC处理BLOB类型字段
以下示例将演示使用spring jdbc更新BLOB类型的字段值,即更新student表中的可用记录. student表的结构如下 - CREATE TABLE student( ID INT NOT ...
- Oracle两个数据库互相访问,DBLink使用-转
测试条件:假设某公司总部在北京,新疆有其下属的一个分公司.在本次测试中,新疆的计算机为本地计算机,即本要的IP地址为:192.168.1.100 北京的总部有一个集中的数据库,其SID是SIDBJ,用 ...