package cn.janvi.ds;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement //开启事务管理;如果mybatis中service实现类中加入事务注解,需要此处添加该注解
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
数据源1的属性映射类(cn.janvi.ds.config.Db1Properties)
package cn.janvi.ds.config;
import java.io.Serializable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "spring.datasource.db1")
public class Db1Properties implements Serializable{
private static final long serialVersionUID = 283848210567696024L;
public String url;
public String username;
public String password;
public String driverClassName;
public Integer maxActive;
public Integer initialSize;
public Integer minIdle;
public Integer maxWait;
public Integer maxPoolPreparedStatementPerConnectionSize;
public Integer timeBetweenEvictionRunsMillis;
public Integer minEvictableIdleTimeMillis;
public Boolean poolPreparedStatements;
// 省略Setter 和 Getter 方法......
}
package cn.janvi.ds.bean;
import java.math.BigDecimal;
import java.util.Date;
public class Emp {
private Short empno;
private String ename;
private String job;
private Short mgr;
private Date hiredate;
private BigDecimal sal;
private BigDecimal comm;
private Short deptno;
// 省略... SETTER AND GETTER
}
package cn.janvi.ds.bean;
import java.util.Date;
public class Items {
private Integer id;
private String name;
private Float price;
private String pic;
private Date createtime;
private String detail;
// 省略... SETTER AND GETTER
}
Mapper(使用mybatis的逆向工程生成)
package cn.janvi.ds.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import cn.janvi.ds.bean.Emp;
import cn.janvi.ds.bean.EmpExample;
public interface EmpMapper {
int countByExample(EmpExample example);
int deleteByExample(EmpExample example);
int deleteByPrimaryKey(Short empno);
int insert(Emp record);
int insertSelective(Emp record);
List selectByExample(EmpExample example);
Emp selectByPrimaryKey(Short empno);
int updateByExampleSelective(@Param("record") Emp record, @Param("example") EmpExample example);
int updateByExample(@Param("record") Emp record, @Param("example") EmpExample example);
int updateByPrimaryKeySelective(Emp record);
int updateByPrimaryKey(Emp record);
}
package cn.janvi.ds.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import cn.janvi.ds.bean.Items;
import cn.janvi.ds.bean.ItemsExample;
public interface ItemsMapper {
int countByExample(ItemsExample example);
int deleteByExample(ItemsExample example);
int deleteByPrimaryKey(Integer id);
int insert(Items record);
int insertSelective(Items record);
List selectByExampleWithBLOBs(ItemsExample example);
List selectByExample(ItemsExample example);
Items selectByPrimaryKey(Integer id);
int updateByExampleSelective(@Param("record") Items record, @Param("example") ItemsExample example);
int updateByExampleWithBLOBs(@Param("record") Items record, @Param("example") ItemsExample example);
int updateByExample(@Param("record") Items record, @Param("example") ItemsExample example);
int updateByPrimaryKeySelective(Items record);
int updateByPrimaryKeyWithBLOBs(Items record);
int updateByPrimaryKey(Items record);
}
Mapper对应的.xml文件
EmpMapper.xml
and ${criterion.condition}
and ${criterion.condition} #{criterion.value}
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
and ${criterion.condition}
#{listItem}
and ${criterion.condition}
and ${criterion.condition} #{criterion.value}
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
and ${criterion.condition}
#{listItem}
EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO
delete from EMP
where EMPNO = #{empno,jdbcType=DECIMAL}
delete from EMP
insert into EMP (EMPNO, ENAME, JOB,
MGR, HIREDATE, SAL, COMM,
DEPTNO)
values (#{empno,jdbcType=DECIMAL}, #{ename,jdbcType=VARCHAR}, #{job,jdbcType=VARCHAR},
#{mgr,jdbcType=DECIMAL}, #{hiredate,jdbcType=DATE}, #{sal,jdbcType=DECIMAL}, #{comm,jdbcType=DECIMAL},
#{deptno,jdbcType=DECIMAL})
insert into EMP
EMPNO,
ENAME,
JOB,
MGR,
HIREDATE,
SAL,
COMM,
DEPTNO,
#{empno,jdbcType=DECIMAL},
#{ename,jdbcType=VARCHAR},
#{job,jdbcType=VARCHAR},
#{mgr,jdbcType=DECIMAL},
#{hiredate,jdbcType=DATE},
#{sal,jdbcType=DECIMAL},
#{comm,jdbcType=DECIMAL},
#{deptno,jdbcType=DECIMAL},
update EMP
EMPNO = #{record.empno,jdbcType=DECIMAL},
ENAME = #{record.ename,jdbcType=VARCHAR},
JOB = #{record.job,jdbcType=VARCHAR},
MGR = #{record.mgr,jdbcType=DECIMAL},
HIREDATE = #{record.hiredate,jdbcType=DATE},
SAL = #{record.sal,jdbcType=DECIMAL},
COMM = #{record.comm,jdbcType=DECIMAL},
DEPTNO = #{record.deptno,jdbcType=DECIMAL},
update EMP
set EMPNO = #{record.empno,jdbcType=DECIMAL},
ENAME = #{record.ename,jdbcType=VARCHAR},
JOB = #{record.job,jdbcType=VARCHAR},
MGR = #{record.mgr,jdbcType=DECIMAL},
HIREDATE = #{record.hiredate,jdbcType=DATE},
SAL = #{record.sal,jdbcType=DECIMAL},
COMM = #{record.comm,jdbcType=DECIMAL},
DEPTNO = #{record.deptno,jdbcType=DECIMAL}
update EMP
ENAME = #{ename,jdbcType=VARCHAR},
JOB = #{job,jdbcType=VARCHAR},
MGR = #{mgr,jdbcType=DECIMAL},
HIREDATE = #{hiredate,jdbcType=DATE},
SAL = #{sal,jdbcType=DECIMAL},
COMM = #{comm,jdbcType=DECIMAL},
DEPTNO = #{deptno,jdbcType=DECIMAL},
where EMPNO = #{empno,jdbcType=DECIMAL}
update EMP
set ENAME = #{ename,jdbcType=VARCHAR},
JOB = #{job,jdbcType=VARCHAR},
MGR = #{mgr,jdbcType=DECIMAL},
HIREDATE = #{hiredate,jdbcType=DATE},
SAL = #{sal,jdbcType=DECIMAL},
COMM = #{comm,jdbcType=DECIMAL},
DEPTNO = #{deptno,jdbcType=DECIMAL}
where EMPNO = #{empno,jdbcType=DECIMAL}
ItemsMapper.xml
and ${criterion.condition}
and ${criterion.condition} #{criterion.value}
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
and ${criterion.condition}
#{listItem}
and ${criterion.condition}
and ${criterion.condition} #{criterion.value}
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
and ${criterion.condition}
#{listItem}
id, name, price, pic, createtime
detail
delete from items
where id = #{id,jdbcType=INTEGER}
delete from items
insert into items (id, name, price,
pic, createtime, detail
)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{price,jdbcType=REAL},
#{pic,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, #{detail,jdbcType=LONGVARCHAR}
)
insert into items
id,
name,
price,
pic,
createtime,
detail,
#{id,jdbcType=INTEGER},
#{name,jdbcType=VARCHAR},
#{price,jdbcType=REAL},
#{pic,jdbcType=VARCHAR},
#{createtime,jdbcType=TIMESTAMP},
#{detail,jdbcType=LONGVARCHAR},
update items
id = #{record.id,jdbcType=INTEGER},
name = #{record.name,jdbcType=VARCHAR},
price = #{record.price,jdbcType=REAL},
pic = #{record.pic,jdbcType=VARCHAR},
createtime = #{record.createtime,jdbcType=TIMESTAMP},
detail = #{record.detail,jdbcType=LONGVARCHAR},
update items
set id = #{record.id,jdbcType=INTEGER},
name = #{record.name,jdbcType=VARCHAR},
price = #{record.price,jdbcType=REAL},
pic = #{record.pic,jdbcType=VARCHAR},
createtime = #{record.createtime,jdbcType=TIMESTAMP},
detail = #{record.detail,jdbcType=LONGVARCHAR}
update items
set id = #{record.id,jdbcType=INTEGER},
name = #{record.name,jdbcType=VARCHAR},
price = #{record.price,jdbcType=REAL},
pic = #{record.pic,jdbcType=VARCHAR},
createtime = #{record.createtime,jdbcType=TIMESTAMP}
update items
name = #{name,jdbcType=VARCHAR},
price = #{price,jdbcType=REAL},
pic = #{pic,jdbcType=VARCHAR},
createtime = #{createtime,jdbcType=TIMESTAMP},
detail = #{detail,jdbcType=LONGVARCHAR},
where id = #{id,jdbcType=INTEGER}
update items
set name = #{name,jdbcType=VARCHAR},
price = #{price,jdbcType=REAL},
pic = #{pic,jdbcType=VARCHAR},
createtime = #{createtime,jdbcType=TIMESTAMP},
detail = #{detail,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=INTEGER}
update items
set name = #{name,jdbcType=VARCHAR},
price = #{price,jdbcType=REAL},
pic = #{pic,jdbcType=VARCHAR},
createtime = #{createtime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
service 接口
package cn.janvi.ds.service;
import java.util.List;
import cn.janvi.ds.bean.Emp;
public interface EmpService {
List findAll();
}
package cn.janvi.ds.service;
import java.util.List;
import com.github.pagehelper.PageInfo;
import cn.janvi.ds.bean.Items;
public interface ItemsService {
List findAll();
PageInfo findByPage(int page,int rows);
int add(Items items);
}
这里写点抛砖引玉,希望大家能把自己整理的问题及解决方法晾出来,Mark一下,利人利己。
出现问题先搜一下文档上有没有,再看看度娘有没有,再看看论坛有没有。有报错要看日志。下面简单罗列下常见的问题,大多文档上都有提到的。
1、repeated column width is largerthan paper width:
这个看这段话应该是很好理解的。比如做的模板页面宽度只能放
这个问题我实在是为整个 springsource 的员工蒙羞
如果大家使用 spring 控制事务,使用 Open Session In View 模式,
com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.
简单模拟实现数据库连接池
实例1:
package com.bijian.thread;
public class DB {
//private static final int MAX_COUNT = 10;
private static final DB instance = new DB();
private int count = 0;
private i
using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace WindowsFormsApplication1
{
Configuring Spring and JTA without full Java EE
http://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/
Spring doc -Transaction Management
http://docs.spring.io/spri