这里介绍的mybatis比较简单, 我做为一个初学者, 记录下个人在学习中方法, 如果那里出错, 希望读者朋友们见谅.

首先这里介绍一下我们下面用的表结构:

author表是保存了作者的个人信息, 因为我们在这里做测试, 所以就简单的定义几个字段.

blog表是保存谁写了博客的内容, 这里也是几个简单的字段.

comment表是保存对哪篇博客评论, 也是几个简单的字段.

注意: 这三张表的id都是自增型, 你也可以做其他的改变, 这里是为了方便.

下面给出了几张表格创建的sql语句:

  1. CREATE TABLE `author` (
  2. `id` int(11) NOT NULL AUTO_INCREMENT,
  3. `name` varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  4. `age` int(5) NULL DEFAULT NULL,
  5. `email` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  6. `country` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  7. PRIMARY KEY (`id`)
  8. );
  9.  
  10. CREATE TABLE `blog` (
  11. `id` int(11) NOT NULL AUTO_INCREMENT,
  12. `authorid` int(11) NULL DEFAULT NULL,
  13. `title` varchar(35) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  14. `mainbody` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
  15. `creattime` varchar(70) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  16. PRIMARY KEY (`id`)
  17. );
  18.  
  19. CREATE TABLE `comment` (
  20. `id` int(11) NOT NULL AUTO_INCREMENT,
  21. `blogid` int(11) NULL DEFAULT NULL,
  22. `content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
  23. `creattime` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  24. PRIMARY KEY (`id`)
  25. );

使用maven+springmvc+mabatis+spring搭建web环境, 可以参考博客: https://www.cnblogs.com/jay36/p/7762448.html, 这里就不详细的介绍了.

这里主要介绍mybatis的用法, 首先使用Mybatis Generator生成pojo/dao/mapping三个文件, 即实体类、DAO接口和Mapping映射文件.

可以参考博客:  https://blog.csdn.net/zhshulin/article/details/23912615, 下面就开始简单介绍Mybatis的使用.

 1.  看一下三个表pojo(Plain Ordinary Java Object), 即实体类

  1. package com.springdemo.pojo;
  2. public class Author {
  3. private Integer id;
  4. private String name;
  5. private Integer age;
  6. private String email;
  7. private String country;
  8. /* getting and setting function */
  9. }
  10. package com.springdemo.pojo;
  11. public class Blog {
  12. private Integer id;
  13. private Integer authorid;
  14. private String title;
  15. private String creattime;
  16. private String mainbody;
  17. /* getting and setting function */
  18. }
  19. package com.springdemo.pojo;
  20. public class Comment {
  21. private Integer id;
  22. private Integer blogid;
  23. private String creattime;
  24. private String content;
  25. /* getting and setting function */
  26. }

2.  再看一下三个表的dao(Data Access Object), 即dao接口

  1. package com.springdemo.dao
  2. public interface AuthorMapper {
  3. int deleteByPrimaryKey(Integer id);
  4. int insert(Author record);
  5. int insertSelective(Author record);
  6. Author selectByPrimaryKey(Integer id);
  7. int updateByPrimaryKeySelective(Author record);
  8. int updateByPrimaryKey(Author record);
  9. }
  10. package com.springdemo.dao
  11. public interface BlogMapper {
  12. int deleteByPrimaryKey(Integer id);
  13. int insert(Blog record);
  14. int insertSelective(Blog record);
  15. Blog selectByPrimaryKey(Integer id);
  16. int updateByPrimaryKeySelective(Blog record);
  17. int updateByPrimaryKeyWithBLOBs(Blog record);
  18. int updateByPrimaryKey(Blog record);
  19. }
  20. package com.springdemo.dao
  21. public interface CommentMapper {
  22. int deleteByPrimaryKey(Integer id);
  23. int insert(Comment record);
  24. int insertSelective(Comment record);
  25. Comment selectByPrimaryKey(Integer id);
  26. int updateByPrimaryKeySelective(Comment record);
  27. int updateByPrimaryKeyWithBLOBs(Comment record);
  28. int updateByPrimaryKey(Comment record);
  29. }

3.  再看一下三个表的mapping, 即Mapping映射

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.springdemo.dao.AuthorMapper" >
  4. <resultMap id="BaseResultMap" type="com.springdemo.pojo.Author" >
  5. <id column="id" property="id" jdbcType="INTEGER" />
  6. <result column="name" property="name" jdbcType="VARCHAR" />
  7. <result column="age" property="age" jdbcType="INTEGER" />
  8. <result column="email" property="email" jdbcType="VARCHAR" />
  9. <result column="country" property="country" jdbcType="VARCHAR" />
  10. </resultMap>
  11. <sql id="Base_Column_List" >
  12. id, name, age, email, country
  13. </sql>
  14. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  15. select
  16. <include refid="Base_Column_List" />
  17. from author
  18. where id = #{id,jdbcType=INTEGER}
  19. </select>
  20. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  21. delete from author
  22. where id = #{id,jdbcType=INTEGER}
  23. </delete>
  24. <insert id="insert" parameterType="com.springdemo.pojo.Author" >
  25. insert into author (id, name, age,
  26. email, country)
  27. values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER},
  28. #{email,jdbcType=VARCHAR}, #{country,jdbcType=VARCHAR})
  29. </insert>
  30. <insert id="insertSelective" parameterType="com.springdemo.pojo.Author" >
  31. insert into author
  32. <trim prefix="(" suffix=")" suffixOverrides="," >
  33. <if test="id != null" >
  34. id,
  35. </if>
  36. <if test="name != null" >
  37. name,
  38. </if>
  39. <if test="age != null" >
  40. age,
  41. </if>
  42. <if test="email != null" >
  43. email,
  44. </if>
  45. <if test="country != null" >
  46. country,
  47. </if>
  48. </trim>
  49. <trim prefix="values (" suffix=")" suffixOverrides="," >
  50. <if test="id != null" >
  51. #{id,jdbcType=INTEGER},
  52. </if>
  53. <if test="name != null" >
  54. #{name,jdbcType=VARCHAR},
  55. </if>
  56. <if test="age != null" >
  57. #{age,jdbcType=INTEGER},
  58. </if>
  59. <if test="email != null" >
  60. #{email,jdbcType=VARCHAR},
  61. </if>
  62. <if test="country != null" >
  63. #{country,jdbcType=VARCHAR},
  64. </if>
  65. </trim>
  66. </insert>
  67. <update id="updateByPrimaryKeySelective" parameterType="com.springdemo.pojo.Author" >
  68. update author
  69. <set >
  70. <if test="name != null" >
  71. name = #{name,jdbcType=VARCHAR},
  72. </if>
  73. <if test="age != null" >
  74. age = #{age,jdbcType=INTEGER},
  75. </if>
  76. <if test="email != null" >
  77. email = #{email,jdbcType=VARCHAR},
  78. </if>
  79. <if test="country != null" >
  80. country = #{country,jdbcType=VARCHAR},
  81. </if>
  82. </set>
  83. where id = #{id,jdbcType=INTEGER}
  84. </update>
  85. <update id="updateByPrimaryKey" parameterType="com.springdemo.pojo.Author" >
  86. update author
  87. set name = #{name,jdbcType=VARCHAR},
  88. age = #{age,jdbcType=INTEGER},
  89. email = #{email,jdbcType=VARCHAR},
  90. country = #{country,jdbcType=VARCHAR}
  91. where id = #{id,jdbcType=INTEGER}
  92. </update>
  93. </mapper>
  94.  
  95. <?xml version="1.0" encoding="UTF-8" ?>
  96. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  97. <mapper namespace="com.springdemo.dao.BlogMapper" >
  98. <resultMap id="BaseResultMap" type="com.springdemo.pojo.Blog" >
  99. <id column="id" property="id" jdbcType="INTEGER" />
  100. <result column="authorid" property="authorid" jdbcType="INTEGER" />
  101. <result column="title" property="title" jdbcType="VARCHAR" />
  102. <result column="creattime" property="creattime" jdbcType="VARCHAR" />
  103. </resultMap>
  104. <resultMap id="ResultMapWithBLOBs" type="com.springdemo.pojo.Blog" extends="BaseResultMap" >
  105. <result column="mainbody" property="mainbody" jdbcType="LONGVARCHAR" />
  106. </resultMap>
  107. <sql id="Base_Column_List" >
  108. id, authorid, title, creattime
  109. </sql>
  110. <sql id="Blob_Column_List" >
  111. mainbody
  112. </sql>
  113. <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
  114. select
  115. <include refid="Base_Column_List" />
  116. ,
  117. <include refid="Blob_Column_List" />
  118. from blog
  119. where id = #{id,jdbcType=INTEGER}
  120. </select>
  121. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  122. delete from blog
  123. where id = #{id,jdbcType=INTEGER}
  124. </delete>
  125. <insert id="insert" parameterType="com.springdemo.pojo.Blog" >
  126. insert into blog (id, authorid, title,
  127. creattime, mainbody)
  128. values (#{id,jdbcType=INTEGER}, #{authorid,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR},
  129. #{creattime,jdbcType=VARCHAR}, #{mainbody,jdbcType=LONGVARCHAR})
  130. </insert>
  131. <insert id="insertSelective" parameterType="com.springdemo.pojo.Blog" >
  132. insert into blog
  133. <trim prefix="(" suffix=")" suffixOverrides="," >
  134. <if test="id != null" >
  135. id,
  136. </if>
  137. <if test="authorid != null" >
  138. authorid,
  139. </if>
  140. <if test="title != null" >
  141. title,
  142. </if>
  143. <if test="creattime != null" >
  144. creattime,
  145. </if>
  146. <if test="mainbody != null" >
  147. mainbody,
  148. </if>
  149. </trim>
  150. <trim prefix="values (" suffix=")" suffixOverrides="," >
  151. <if test="id != null" >
  152. #{id,jdbcType=INTEGER},
  153. </if>
  154. <if test="authorid != null" >
  155. #{authorid,jdbcType=INTEGER},
  156. </if>
  157. <if test="title != null" >
  158. #{title,jdbcType=VARCHAR},
  159. </if>
  160. <if test="creattime != null" >
  161. #{creattime,jdbcType=VARCHAR},
  162. </if>
  163. <if test="mainbody != null" >
  164. #{mainbody,jdbcType=LONGVARCHAR},
  165. </if>
  166. </trim>
  167. </insert>
  168. <update id="updateByPrimaryKeySelective" parameterType="com.springdemo.pojo.Blog" >
  169. update blog
  170. <set >
  171. <if test="authorid != null" >
  172. authorid = #{authorid,jdbcType=INTEGER},
  173. </if>
  174. <if test="title != null" >
  175. title = #{title,jdbcType=VARCHAR},
  176. </if>
  177. <if test="creattime != null" >
  178. creattime = #{creattime,jdbcType=VARCHAR},
  179. </if>
  180. <if test="mainbody != null" >
  181. mainbody = #{mainbody,jdbcType=LONGVARCHAR},
  182. </if>
  183. </set>
  184. where id = #{id,jdbcType=INTEGER}
  185. </update>
  186. <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.springdemo.pojo.Blog" >
  187. update blog
  188. set authorid = #{authorid,jdbcType=INTEGER},
  189. title = #{title,jdbcType=VARCHAR},
  190. creattime = #{creattime,jdbcType=VARCHAR},
  191. mainbody = #{mainbody,jdbcType=LONGVARCHAR}
  192. where id = #{id,jdbcType=INTEGER}
  193. </update>
  194. <update id="updateByPrimaryKey" parameterType="com.springdemo.pojo.Blog" >
  195. update blog
  196. set authorid = #{authorid,jdbcType=INTEGER},
  197. title = #{title,jdbcType=VARCHAR},
  198. creattime = #{creattime,jdbcType=VARCHAR}
  199. where id = #{id,jdbcType=INTEGER}
  200. </update>
  201. </mapper>
  202.  
  203. <?xml version="1.0" encoding="UTF-8" ?>
  204. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  205. <mapper namespace="com.springdemo.dao.CommentMapper" >
  206. <resultMap id="BaseResultMap" type="com.springdemo.pojo.Comment" >
  207. <id column="id" property="id" jdbcType="INTEGER" />
  208. <result column="blogid" property="blogid" jdbcType="INTEGER" />
  209. <result column="creattime" property="creattime" jdbcType="VARCHAR" />
  210. </resultMap>
  211. <resultMap id="ResultMapWithBLOBs" type="com.springdemo.pojo.Comment" extends="BaseResultMap" >
  212. <result column="content" property="content" jdbcType="LONGVARCHAR" />
  213. </resultMap>
  214. <sql id="Base_Column_List" >
  215. id, blogid, creattime
  216. </sql>
  217. <sql id="Blob_Column_List" >
  218. content
  219. </sql>
  220. <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
  221. select
  222. <include refid="Base_Column_List" />
  223. ,
  224. <include refid="Blob_Column_List" />
  225. from comment
  226. where id = #{id,jdbcType=INTEGER}
  227. </select>
  228. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  229. delete from comment
  230. where id = #{id,jdbcType=INTEGER}
  231. </delete>
  232. <insert id="insert" parameterType="com.springdemo.pojo.Comment" >
  233. insert into comment (id, blogid, creattime,
  234. content)
  235. values (#{id,jdbcType=INTEGER}, #{blogid,jdbcType=INTEGER}, #{creattime,jdbcType=VARCHAR},
  236. #{content,jdbcType=LONGVARCHAR})
  237. </insert>
  238. <insert id="insertSelective" parameterType="com.springdemo.pojo.Comment" >
  239. insert into comment
  240. <trim prefix="(" suffix=")" suffixOverrides="," >
  241. <if test="id != null" >
  242. id,
  243. </if>
  244. <if test="blogid != null" >
  245. blogid,
  246. </if>
  247. <if test="creattime != null" >
  248. creattime,
  249. </if>
  250. <if test="content != null" >
  251. content,
  252. </if>
  253. </trim>
  254. <trim prefix="values (" suffix=")" suffixOverrides="," >
  255. <if test="id != null" >
  256. #{id,jdbcType=INTEGER},
  257. </if>
  258. <if test="blogid != null" >
  259. #{blogid,jdbcType=INTEGER},
  260. </if>
  261. <if test="creattime != null" >
  262. #{creattime,jdbcType=VARCHAR},
  263. </if>
  264. <if test="content != null" >
  265. #{content,jdbcType=LONGVARCHAR},
  266. </if>
  267. </trim>
  268. </insert>
  269. <update id="updateByPrimaryKeySelective" parameterType="com.springdemo.pojo.Comment" >
  270. update comment
  271. <set >
  272. <if test="blogid != null" >
  273. blogid = #{blogid,jdbcType=INTEGER},
  274. </if>
  275. <if test="creattime != null" >
  276. creattime = #{creattime,jdbcType=VARCHAR},
  277. </if>
  278. <if test="content != null" >
  279. content = #{content,jdbcType=LONGVARCHAR},
  280. </if>
  281. </set>
  282. where id = #{id,jdbcType=INTEGER}
  283. </update>
  284. <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.springdemo.pojo.Comment" >
  285. update comment
  286. set blogid = #{blogid,jdbcType=INTEGER},
  287. creattime = #{creattime,jdbcType=VARCHAR},
  288. content = #{content,jdbcType=LONGVARCHAR}
  289. where id = #{id,jdbcType=INTEGER}
  290. </update>
  291. <update id="updateByPrimaryKey" parameterType="com.springdemo.pojo.Comment" >
  292. update comment
  293. set blogid = #{blogid,jdbcType=INTEGER},
  294. creattime = #{creattime,jdbcType=VARCHAR}
  295. where id = #{id,jdbcType=INTEGER}
  296. </update>
  297. </mapper>

mybatis的使用, 关键在于要要写好mapping映射, 使用工具生成的是最简单的curd的方法, 现在我们来增加一个我们自定义的方法.

首先在mapping的文件中写一个映射, 我们就在BlogMapper.xml文件中写,代码如下:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.springdemo.dao.BlogMapper" >
  4. ......
  5. <insert id="insertBlogByList" useGeneratedKeys="true"
  6. keyProperty="id" parameterType="java.util.List">
  7. insert into blog (authorid, title, creattime, mainbody) values
  8. <foreach item="item" collection="list" separator=",">
  9. (#{item.authorid,jdbcType=INTEGER}, #{item.title,jdbcType=VARCHAR},
  10. #{item.creattime,jdbcType=VARCHAR}, #{item.mainbody,jdbcType=LONGVARCHAR})
  11. </foreach>
  12. </insert>
  13. ......
  14. </mapper>
  15.  
  16. 这段xml的代码主要就是批量插入数据, 而且id是自增长的,  数据以list的形式传入进来, 然后循环插入到blog表中.

然后我们要在BlogMapper.java的dao中加一个接口, 代码如下:

  1. package com.springdemo.dao;
  2. public interface BlogMapper {
  3. ......
  4. int insertBlogByList(List<Blog> listBlog);
  5. ......
  6. }
    注意这里的接口名字要和我们之前在xml中加入的id值相同才行, 因为这样mybatis才会映射.
    即在BlogMapper.xml中写的insert语句idinsertBlogByList,
    那么这里的定义的接口必须也是这个, 而且参数的类型也必须一样, 这一点切记。

最后我们要在controller中去调用(因为这里我是用springmvc写的,所有用mvc思想去写调用,你也可以随便写一个方法去调用, 这里给出我的调用方法):

  1. //下面是BlogController.java的代码
  2. package com.springdemo.controller;
  3.  
  4. @Controller
  5. @RequestMapping(value = "/blog")
  6. public class BlogController {
  7.  
  8. private static final Logger LOG = LogManager.getLogger();
  9.  
  10. @Autowired
  11. private BlogService blogService;
  12.  
  13.    //这里是把前端的值获取到,然后再存入到数据库中, 最后返回状态
  14. @RequestMapping(value="/insert", method = RequestMethod.POST)
  15. public void insertBlog(HttpServletRequest request, HttpServletResponse response) {
  16. String status = "{\"status\":\"failure\"}";
  17. int authorid = Integer.parseInt(request.getParameter("authorid"));
  18. String title = String.valueOf(request.getParameter("title"));
  19. String mainbody = String.valueOf(request.getParameter("mainbody"));
  20.  
  21. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  22. Date now = new Date();
  23. String creattime = df.format(now);
  24.  
  25. List<Blog> listBlog = new ArrayList<Blog>();
  26. Blog blog = new Blog();
  27. blog.setAuthorid(authorid);
  28. blog.setTitle(title);
  29. blog.setMainbody(mainbody);
  30. blog.setCreattime(creattime);
  31. listBlog.add(blog);
  32.  
  33. int affectRow = blogService.insertBlogByList(listBlog);
  34. if (affectRow != 0) {
  35. status = "{\"status\":\"success\"}";
  36. }
  37.  
  38. response.setContentType("text/html;UTF-8");
  39. try (PrintWriter writer = response.getWriter();) {
  40. writer.write(status);
  41. writer.flush();
  42. } catch (IOException e) {
  43. LOG.error(e.getMessage(), e);
  44. }
  45. }
  46. }
  47.  
  48. ----------------------------------------------------------
  49. // 下面是BlogService.java的代码
  50. package com.springdemo.service;
  51. import java.util.List;

  52. // 这里不需要继承BlogMapper接口, 通过spring注解直接使用
  53. @Service(value="blogService")
  54. public class BlogService {
  55.  
  56. @Resource
  57. private BlogMapper blogMapper;
  58.  
  59. public int insertBlogByList(List<Blog> listBlog) {
  60. int affectRow = 0;
  61. affectRow = this.blogMapper.insertBlogByList(listBlog);
  62. return affectRow;
  63. }
  64.  
  65. }

这样就简单的完成了在xml中建立sql语句, 然后通过映射转换到java中, 最后去执行.

待续......

Mybatis介绍(一)的更多相关文章

  1. MyBatis - 介绍、简单入门程序

    JDBC编程中的问题     1. 将SQL语句硬编码到Java代码,不利于系统维护.         设想如何解决:将SQL单独抽取出来,在配置文件(xml方式.properties文件)进行配置. ...

  2. Mybatis学习笔记(一) —— mybatis介绍

    一.Mybatis介绍 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名 ...

  3. (转)MyBatis框架的学习(一)——MyBatis介绍

    http://blog.csdn.net/yerenyuan_pku/article/details/71699343 MyBatis介绍 MyBatis本是apache的一个开源项目iBatis,2 ...

  4. MyBatis 介绍

    MyBatis 介绍 MyBatis 是一款优秀的 ORM(Object Relational Mapping,对象关系映射)框架,它可以通过对象和数据库之间的映射,将程序中的对象自动存储到数据库中. ...

  5. mybatis介绍--基于个人学习JavaWeb的使用

    mybatis介绍 该博文放在javaWeb系列下,目的是记录我们javaWeb阶段所学的知识 @time=2022/3/11/11:52(最近休息玩了两天,今天重新启动生活) 一.mybatis发展 ...

  6. mybatis介绍与环境搭建

    一.不用纯jdbc的原因,即缺点. 1.数据库理解,使用时创建,不用时释放,会对数据库进行频繁的链接开启和关闭,造成数据库的资源浪费,影响数据库的性能.设想:使用数据库的连接池.2.将sql语句硬编码 ...

  7. 深入浅出MyBatis:JDBC和MyBatis介绍

    JDBC相关概念 Java程序都是通过JDBC连接数据库的,通过SQL对数据库编程,JDBC是由SUN公司提出的一些列规范,只定义了接口规范,具体实现由各个数据库厂商去实现,它是一种典型的桥接模式. ...

  8. MyBatis介绍及使用

    一.介绍: 1.MyBatis实际上是Ibatis3.0版本以后的持久化层框架[也就是和数据库打交道的框架]! 2.和数据库打交道的技术有: 原生的JDBC技术--->Spring的JdbcTe ...

  9. mybatis介绍安装

    MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以对配置和原生Map使用简单 ...

随机推荐

  1. 《精通Spring4.X企业应用开发实战》读后感第六章(容器事件)

  2. BSGS(大小步)算法

    BSGS算法主要用于求解形如ax≡b(mod p)的式子中x的值. 在这里我们不妨设 x=k1*n-k2 这时我们就可以将式子转化为 ak1*n≡b*ak2(mod p) 这里的n我们设为√p,所以我 ...

  3. 12、scala隐式转换与隐式参数

    一.隐式转换 1.介绍 Scala提供的隐式转换和隐式参数功能,是非常有特色的功能.是Java等编程语言所没有的功能.它可以允许你手动指定,将某种类型的对象转换成其他类型的对象. 通过这些功能,可以实 ...

  4. 子元素应该margin-top影响父元素的解决办法

    在子元素设置margin-top,有时会带着父元素一起移动. 原因: Outer Div [margin: 0 auto] Inner Div [margin-top: 10px] 根据CSS2.1盒 ...

  5. android build system resource links

    总体结构,参见这里:http://www.jayway.com/2012/10/24/a-practical-approach-to-the-aosp-build-system/ 一般应用的Andro ...

  6. 使用Django创建一个后端是SQLSERVER的简单系统(一)Django连接SQLServer数据库

    window环境下Django连接SQLSERVER, 1.创建项目: 2.创建application: 3.使用pycharm打开项目,如下图: 4.配置虚拟环境: 安装Django\pyodbc\ ...

  7. JSONCPP开发环境搭建

    环境设置 项目地址 https://github.com/open-source-parsers/jsoncpp.git 操作系统 64位 Fedora 24 安装jsoncpp $ git clon ...

  8. Start and Stop Bitbucket Server

    Starting and stopping Bitbucket Server This page describes the various ways you can start or stop Bi ...

  9. php路径问题

    ./ 是在当前目录开始寻找文件/ 是在下一级目录开始寻找文件 ../ 这个是在上一级目录开始寻找文件 $_SERVER['DOCUMENT_ROOT']获取站点根目录 __FILE__获取当前文件的完 ...

  10. Git 2016视频教程

    http://blog.csdn.net/biggbang/article/details/50830331