Springboot 学习笔记 之 Day 3 JdbcTemplate thymeleaf 页面 做一个简易的bug系统
https://www.cnblogs.com/qianjinyan/p/10065160.html
之前关于要做的系统的数据结构
今天实现连接mssql server,查询出所有buglist的效果
实现方法极其简单,如下图
Bug类对象中列出字段
package com.jasmine.demo.bean; public class Bug { private long id; private String pname; private String crname; private String crnum; private String tasknum; private String oname; private String description; private String rca; private String solution; private String developer; private String tester; private String creationdt; private String updatedt; public long getId() { return id; } public void setId(long id) { this.id = id; } public String getPname() { return pname; } public void setPname(String pname) { this.pname = pname; } public String getCrname() { return crname; } public void setCrname(String crname) { this.crname = crname; } public String getCrnum() { return crnum; } public void setCrnum(String crnum) { this.crnum = crnum; } public String getTasknum() { return tasknum; } public void setTasknum(String tasknum) { this.tasknum = tasknum; } public String getOname() { return oname; } public void setOname(String oname) { this.oname = oname; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getRca() { return rca; } public void setRca(String rca) { this.rca = rca; } public String getSolution() { return solution; } public void setSolution(String solution) { this.solution = solution; } public String getDeveloper() { return developer; } public void setDeveloper(String developer) { this.developer = developer; } public String getTester() { return tester; } public void setTester(String tester) { this.tester = tester; } public String getCreationdt() { return creationdt; } public void setCreationdt(String creationdt) { this.creationdt = creationdt; } public String getUpdatedt() { return updatedt; } public void setUpdatedt(String updatedt) { this.updatedt = updatedt; } @Override public String toString() { return "Bug{" + "id=" + id + ", pname='" + pname + '\'' + ", crname='" + crname + '\'' + ", crnum='" + crnum + '\'' + ", tasknum='" + tasknum + '\'' + ", oname='" + oname + '\'' + ", description='" + description + '\'' + ", rca='" + rca + '\'' + ", solution='" + solution + '\'' + ", developer='" + developer + '\'' + ", tester='" + tester + '\'' + ", creationdt='" + creationdt + '\'' + ", updatedt='" + updatedt + '\'' + '}'; } public Bug() { super(); } public Bug(long id, String pname, String crname, String crnum, String tasknum, String oname, String description, String rca, String solution, String developer, String tester, String creationdt, String updatedt) { this.id = id; this.pname = pname; this.crname = crname; this.crnum = crnum; this.tasknum = tasknum; this.oname = oname; this.description = description; this.rca = rca; this.solution = solution; this.developer = developer; this.tester = tester; this.creationdt = creationdt; this.updatedt = updatedt; } }
BugService 接口中定义了增删查改等方法
具体实现是在对应的impl中
package com.jasmine.demo.service; import com.jasmine.demo.bean.Bug; import java.util.List; public interface BugService { List<Bug> findAll(); Bug findById(int id); int create(String pname,String crname,String crnum, String tasknum, String oname, String description, String rca, String solution, String developer, String tester); int update(long id, String crnum, String tasknum, String oname, String description, String rca, String solution, String developer, String tester); int deleteByID(int id); }
package com.jasmine.demo.service.impl; import com.jasmine.demo.bean.Bug; import com.jasmine.demo.jdbc.BugRowMapper; import com.jasmine.demo.service.BugService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import java.util.List; @Service public class BugServiceImpl implements BugService { @Autowired private JdbcTemplate jdbcTemplate; @Override public List<Bug> findAll() { String sql = "SELECT BUG_ID,PROJECT_NAME,CR_NAME,BUG_CR_NUM,BUG_TASK_NUM,OBJECT_NAME,BUG_DESCRIPTION\n" + ",BUG_RCA,BUG_SOLUTION,B.EMPLOY_NAME DEVELOPER,A.EMPLOY_NAME TESTER,QA_CREATIONDT,QA_UPDATEDT,BUG_DELETED_FLAG\n" + "FROM QA_BUGLIST\n" + "JOIN QA_PROJECT ON BUG_PROJECT_ID = PROJECT_ID\n" + "JOIN QA_CRTYPE ON CR_ID = BUG_CR_TYPE_ID\n" + "JOIN QA_RTYPE ON OBJECT_ID = QA_TYPE_ID\n" + "JOIN QA_EMPLOY A ON A.[EMPLOY_ID] = QA_TESTER_ID AND A.[EMPLOY_GROUP] = 1 ---表示测试\n" + "JOIN QA_EMPLOY B ON B.[EMPLOY_ID] = QA_ASSIGNEE_ID AND B.[EMPLOY_GROUP] = 2 ---表示开发人员\n" + "WHERE BUG_DELETED_FLAG =0 order by 1 desc"; List<Bug> bugs = jdbcTemplate.query(sql,new BugRowMapper() ); return bugs; } @Override public Bug findById(int id) { String sql = "SELECT BUG_ID,PROJECT_NAME,CR_NAME,isnull(BUG_CR_NUM,'') as BUG_CR_NUM,isnull(BUG_TASK_NUM,'') as BUG_TASK_NUM,OBJECT_NAME,isnull(BUG_DESCRIPTION,'') as BUG_DESCRIPTION\n" + ",isnull(BUG_RCA,'') as BUG_RCA,isnull(BUG_SOLUTION,'') as BUG_SOLUTION,B.EMPLOY_NAME DEVELOPER,A.EMPLOY_NAME TESTER,QA_CREATIONDT,QA_UPDATEDT,BUG_DELETED_FLAG\n" + "FROM QA_BUGLIST\n" + "JOIN QA_PROJECT ON BUG_PROJECT_ID = PROJECT_ID\n" + "JOIN QA_CRTYPE ON CR_ID = BUG_CR_TYPE_ID\n" + "JOIN QA_RTYPE ON OBJECT_ID = QA_TYPE_ID\n" + "JOIN QA_EMPLOY A ON A.[EMPLOY_ID] = QA_TESTER_ID AND A.[EMPLOY_GROUP] = 1 ---表示测试\n" + "JOIN QA_EMPLOY B ON B.[EMPLOY_ID] = QA_ASSIGNEE_ID AND B.[EMPLOY_GROUP] = 2 ---表示开发人员\n" + "WHERE BUG_DELETED_FLAG =0 and BUG_ID = ?"; Bug bug = jdbcTemplate.queryForObject(sql,new BugRowMapper(),id); return bug; } @Override public int create(String pname,String crname,String crnum, String tasknum, String oname, String description, String rca, String solution, String developer, String tester) { String sql ="INSERT QA_BUGLIST(BUG_PROJECT_ID,BUG_CR_TYPE_ID,BUG_CR_NUM,BUG_TASK_NUM,QA_TYPE_ID,BUG_DESCRIPTION,BUG_RCA,BUG_SOLUTION,QA_ASSIGNEE_ID,QA_TESTER_ID,QA_CREATIONDT,QA_UPDATEDT)\n" + "VALUES(?,?,?,?,?,?,?,?,?,?,GETDATE(),GETDATE())"; return jdbcTemplate.update(sql,pname,crname,crnum,tasknum,oname,description,rca,solution,developer,tester); } @Override public int update(long id, String crnum, String tasknum, String description, String rca, String solution, String developer, String tester,String oname){ String sql = "update QA_BUGLIST set BUG_CR_NUM =?,BUG_TASK_NUM =?,BUG_DESCRIPTION=?,BUG_RCA=?,BUG_SOLUTION= ?,QA_UPDATEDT =getdate() where BUG_ID = ?"; System.out.println(sql); return jdbcTemplate.update(sql,crnum,tasknum,description,rca,solution,id); } @Override public int deleteByID(int id) { String sql = "update QA_BUGLIST set BUG_DELETED_FLAG = 1, BUG_DELETED_COMMENT = '逻辑删除' where BUG_ID = ?"; System.out.println(sql); int count = jdbcTemplate.update(sql,id); return count; } }
DB的配置写在application.xml中
启动类之后,跳转的所有页面,写在controller中,
启动后,打开连接,看到自己的数据
接下来要做的就是让页面好看一点,这样的数据看不清楚
JdbcTemplate
thymeleaf
页面跳转等等,页面比较丑,还没做分页,搜寻条件也没有添加
1. 查看所有bug
2. 查看指定bug的详细信息
点击查看按钮后显示单个bug的信息
3. 删除单列bug信息,点击单个bug信息后面的删除按钮即可删除,删除之前最好有确定按钮用来提示,以免误删
4. 更新,我这边做在查看单个详细列表页面中,如上图,有信息更新按钮,点击后带入原先的参数跳转到更新页面,在新的页面进行更新,然后保存
5. 新增bug页面,在查看所有bug页面有新增按钮,点击进入如下页面,保存进行新增操作
源代码提交在github地址如下:
https://github.com/JasmineQian/SpringbootDemoDay03