1 mysql创建数据库脚本
-PhpMyAdmin SQL转储 - 版本4.2.11-- http://www.phpmyadmin.net----主机:localhost--生成 - 生成时间:2016-08-02 18:13:13:50---服务器版本:5.6.21-- php版本:5.6.3SET sql_mode =“ sql_mode =” no_auto_value__value__zero_zerOne_zerone noteetipe nime_zeero; “+00:00”;/ *!40101设置@old_character_set_client = @@@@@@farne_set_set_client */;/ *!40101 set @old_character_set_set_set_set_set_set_set_set_set_set_set_res_results */;/;/ *!40101 set @old_coll_coll_collation_connection_connection_connection_connection_connection_connection =@@collation_connection-40110 */; ut! Database: `mybatis`---- ------------------------------------------------------------ 表的结构 `Student`--CREATE TABLE IF NOT EXISTS `Student` (`id` int(10) NOT NULL,`name` varchar(256) NOT NULL,`age` int(4) NOT NULL) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;---- 转存表中的数据``sudent'' - 插入``学生'(n id',n name',age')值(1,'zhansan',20); -----丢弃表的索引 - dobled table``table'' - alter table table table table table table add primary primary键( `学生会`id` id` in int(10)not auto_increment,auto_increment = 2;/*!40101设置partinal_set_set_set_client =@old_character_set_set_client*/;/*!40101 set partinal_set_set_set_set_set_set_res_res_res_res_res_ser_set_set_set_set_set_sert_ 40101101 */;
2创建与数据库表学生对应的pojo类
软件包com.mtour.mybatis.demo;导入javax.xml.bind.annotation.xmlrootelement; @xmlrootelementPublic class student name){this.name = name;} public int getage(){return age;} public void setage(int age){this.age = age;}}}3创建映射学生录像师
<?xml版本=“ 1.0” encoding =“ utf-8”?> <!doctype mapper public public' - // mybatis.org//dtd mapper 3.0 // en http://mybatis.org/mybatis.org/dtd/dtd/dtd/mybatis-3-mmybatis-3-mmapper.dtddd"> mmapper.dtddd"> mmapper.mmapper.mmapper.mmapper.mmapper.mmapper.mmapper.mmapper-mmapper-papper< namespace =“ com.mtour.mybatis.demo.studentmapper”> <select ID =“ getStudent” parametypy =“ int” resucttype =“ com.mtour.mybatis.demo.student”
4。创建conf.xml
<?xml版本=“ 1.0” encoding =“ utf-8”?> <!doctype配置公共“ - // mybatis.org//dtd config 3.0 // en” http://mybatis.org/dtd/mmybatis.org/dtd/mybatis-3-3-config.dtddd/ryvent id =“开发”> <transActionManager type =“ jdbc” /> <! - > <dataSource type =“ blibed”> <property name =“ drive” value =“ com.mysql.jdbc.driver” /> <property name =“ url” url“ url” url“ url” value =“ jdbc:mysql:mysql:// localhost:// localhost:3306 /yous <30306 /ybat value =“ root”/> <属性名称=“密码” value =“”/> </dataSource> </emoveruments> </emoverments> <mappers> <mapper resource =“ com/mtour/mtour/mybatis/mybatis/demo/demo/demomapper.xml.xml.xml”/>
5。创建休息资源
package com.mtour.mybatis.demo;import java.io.IOException;import java.io.InputStream;import org.apache.ibatis.session.SqlSession;import org.apache.ibatis.session.SqlSessionFactory;import org.apache.ibatis.session.SqlSessionFactoryBuilder;import javax.ws.rs.get;导入Javax.ws.rs.Path;导入javax.ws.rs.produces;导入Javax.ws.rs.Pathparam;导入javax.ws.rs.core.mediatype; @path(“/student”)公共类demo {static String Resource =“ conf.xml”; static InputStream is = demo.class.getClassLoader()。getResourceasStream(resource); static sqlsessionfactory sessignfactory = new sqlsessionfactory = new sqlsessionfactoryfactorybuilder(new sqlsessionfactorybuilder fublor) Sayhello(){返回“ Hello jersey,第一个演示”; } @get @path(“//{param}”)@produces(“ text/plain; charset; charset = utf-8”)public string sayhellotoutf8(@pathparam(@pathparam(“ param”)字符串用户名){return'hello“ hello” + userName; } @get @path(“/getStudent/{id}”)@produces(mediatype.application_json)公共学生getuserjson(@pathparam(@pathparam(“ id”)字符串ID){integer studentId = integer.value.valueof(id) “ com.mtour.mybatis.demo.studentmapper.getstudent”; student s = session.selectone(statement,studentId); session.close(); return s; return s; }}}6。启动调试
:http://xiazai.vevb.com/201605/yuanma/mybatisdemo(jb51).rar
mybatis读取数据库数据并提供休息,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!