发表于: 2019-11-15 23:05:50
1 1016
spring和mybatis的整合
VIEW:
public class View {
private static final Logger log = LogManager.getLogger(View.class);
public static void main(String[] args){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
StudentService studentService = (StudentService) context.getBean("studentService");
try{
Student student = new Student();
log.info("++++++++++++++++++插入数据+++++++++++++++++++");
long start = System.currentTimeMillis();
student.setName("ksy");
student.setQq(694879425);
student.setSubject("java");
student.setJoinTime(20190625);
student.setSchool("DASD");
student.setWish("欧里给");
student.setTeacher("性感的全全");
student.setWhereKnow("知乎");
student.setCreateAt(2013254);
student.setUpdateAt(20177349);
studentService.insertMethod(student);
long end = System.currentTimeMillis();
log.info("+++++++++++++++++插入数据完成++++++++++++++++++");
log.info("用时:"+(end-start)+"毫秒");
long studentId = student.getId();
log.info("insert id is"+studentId);
}catch (Exception e){
e.printStackTrace();
log.error("ERROR");
}
//删除数据
try {
log.info("++++++++++++++++++删除数据+++++++++++++++++++");
Student student = new Student();
student.setName("k132");
int result= studentService.deleteMethod(student);
boolean flag=result>0? true:false;
log.info(flag);
log.info("+++++++++++++++++删除数据完成++++++++++++++++");
}catch (Exception e){
e.printStackTrace();
log.error("ERROR");
log.error("false");
}
//更新数据
try{
log.info("++++++++++++++++++更新数据+++++++++++++++++++");
Student student = new Student();
student.setId(8494L);
student.setWish("'go to the moon'");
int result = studentService.updateMethod(student);
boolean flag=result>0? true:false;
log.info(flag);
log.info("+++++++++++++++++更新数据完成++++++++++++++++++");
}catch (Exception e) {
e.printStackTrace();
log.error("ERROR");
log.error("return false");
}
//根据姓名查找数据
try{
log.info("+++++++++++++++根据姓名查找数据++++++++++++++++");
Student student=studentService.queryStudentByName("keshiyang");
log.info("结果是:" + student);
}catch (Exception e){
e.printStackTrace();
log.error("ERROR");
}
//根据Id查找数据
try {
log.info("+++++++++++++++根据ID查找数据++++++++++++++++");
Student student = studentService.queryStudentById(16585L);
log.info("结果是: " + student);
}catch (Exception e){
e.printStackTrace();
log.error("ERROR");}
applicationContext:
studentMapper:
遇到的问题:db.properties没设置时区的BUG
还有一个LOG4J报错自己没解决 换了个案列敲 SO SAD...
明天的计划:mybatis也要重写(之前的丢失) 打包上服务器 上传GIT 总结一下
收获 会仿写一个简单的增删改查 用mybatis和spring
评论