自己写的例子,用的人记得自己敲代码修改
这里表现的是数据展示和条件查询(先会简单的查询,然后再学分页)
一、数据展示
二、条件,可以单个或多个
1.2后端实体类
1.3.serviceimpl
1.4.dao
1.5.controller(get或post自己随意)
1.6,前端
请求方法
created:当需要将数据库数据显示到页面时,就可以将获取表数据的方法在created()进行调用,在页面渲染之前就将数据获取
2.
二:多条件或但条件查询。这里写的比较简单字节(先不进行分页,需要一步一步进行)
这里注意注解的使用
2.1这里的dao层和service无非就是再原本的括号里面添加了(Admin admin)的数据,照葫芦画瓢就行
@responseBody 将 Controller 的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到 response 对象的 body 区,通常用来返回 JSON 数据或者 XML 数据。
@RequestBody主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的);而最常用的使用请求体传参的无疑是POST请求了,所以使用@RequestBody接收数据时,一般都用POST方式进行提交。
2.2 mybatis,这里是多条件查询所编辑查询语句
2.3前端
2.4请求
mybatis层
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.dao.AdminDao">
<resultMap id="BaseResultMap" type="com.example.demo.entity.Admin" autoMapping="true">
<result property="username" column="username" jdbcType="VARCHAR"></result>
<result property="password" column="password" jdbcType="VARCHAR"></result>
<result property="datat" column="datat" jdbcType="VARCHAR"></result>
<result property="dataw" column="dataw" jdbcType="VARCHAR"></result>
<result property="shuju" column="shuju" jdbcType="VARCHAR"></result>
<result property="sf" column="sf" jdbcType="VARCHAR"></result>
</resultMap>
//数据展示
<select id="getAll" resultMap="BaseResultMap">
select * from admin
</select>
//条件查询
<select id="tiaoJian" resultMap="BaseResultMap">
select * from admin
<where>
<if test="username!= null and username!= ''">
and username like concat(concat('%',#{username}),'%')
</if>
<if test="sf!= null and sf!= ''">
and sf=#{sf}
</if>
</where>
</select>
</mapper>