springboot+mybatis实现根据条件查询数据库将结果集合循环
遍历显⽰在页⾯上
1、model层  bean类
del;
public class Lamp {
private int id;
//⽀付账单的openid
private String openid;
//发起⼈
private String sname;
//祝福⼈
private String gname;
//灯的位置
private String address;
//点灯的时间如7天
private int cycle;
//灯的类型
private String kinds;
//祝福语
private String content;
//付费的⾦额
private String money;
/
/付费的时间
private String time;
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public String getOpenid() {
return openid;
}
public String getSname() {
return sname;
}
public String getGname() {
return gname;
}
powerpoint无法从所选的文件中插入视频
public String getAddress() {
return address;
}
public int getCycle() {
return cycle;
}
public String getKinds() {
return kinds;
}
public String getContent() {
return content;
}
public String getMoney() {
return money;
}
public String getTime() {
return time;
三角函数图像生成器}
public void setOpenid(String openid) {        this.openid = openid;
}
public void setSname(String sname) {        this.sname = sname;
}
public void setGname(String gname) {        ame = gname;
}
public void setAddress(String address) {        this.address = address;
}
public void setCycle(int cycle) {
wordpress小说网站源码}
public void setKinds(String kinds) {
this.kinds = kinds;
}
public void setContent(String content) {        t = content;
}
public void setMoney(String money) {        = money;
}
public void setTime(String time) {
this.time = time;
}
}
2、在数据库中创建表
3、编写dao层代码
ample.demo.dao;
del.Lamp;
mysql面试题集合import java.util.List;
public interface LampDao {
//插⼊数据
int insert(Lamp l);
//查询数据
List<Lamp> query(String openid);
}
4、实现类
ample.demo.service;
ample.demo.dao.LampDao;
del.Lamp;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class LampService {
@Autowired
private LampDao ld;
public int insert(Lamp l) {
return ld.insert(l);
}
public List<Lamp> query(String openid) {
return ld.query(openid);
}
}
5、编写服务层代码
l;
del.Lamp;
ample.demo.service.LampService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired; import t.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import java.util.List;
@Controller()
@Scope("prototype")
@RequestMapping("/lamp")
public class LampControl {
@Autowired
private LampService us;
@RequestMapping("/query")
public String  query(@Param("openid")String openid, Model model) {        System.out.println("openid:"+openid);
List<Lamp> list_lamp=us.query(openid);
model.addAttribute("list",list_lamp);
//把这个集合发送给my前端页⾯
return "my";
}
@RequestMapping("/insert")
public int insert(@RequestBody Lamp lamp) throws  Exception{
System.out.println("插⼊数据库操作");
return us.insert(lamp);
}
}
6、显⽰页⾯
<!DOCTYPE html>
<html lang="utf-8"  xmlns:th="/1999/xhtml"> <head>
<meta charset="UTF-8">
<title>我的中⼼</title>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<thead>
<th>序号</th>
<th>学⽣id</th>
<th>学⽣姓名</th>
<th>学⽣年龄</th>
css布局的三种机制<th>学⽣课程-课程列表</th>
<th>学⽣课程-课程分数</th>
</thead>
sqlserver多表连接查询<tbody>
<tr th:each="pro,proStat:${list}">
<td th:text="${pro.id}"></td>
<td th:text="${pro.openid}"></td>
<td th:text="${pro.sname}"></td>
<td th:text="${ame}"></td>
<td th:text="${pro.address}"></td>
<td th:text="${le}"></td>
<td th:text="${pro.kinds}"></td>
<td th:text="${t}"></td>
<td th:text="${}"></td>
<td th:text="${pro.time}"></td>
</tr>
</tbody>
</table>
</body>
</html>
最关键的部分是,java代码如何与数据库进⾏连接
连接部分
server:
port: 80
spring:
thymeleaf:
prefix: classpath:/templates/
datasource:
url: jdbc:mysql://localhost:3306/idea?serverTimezone=UTC    username: root
password: 123456
driver-class-name: sql.cj.jdbc.Driver
#server:
#port:8088
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: del
# 测试账号
##⽀付的部分

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。