概述
博客概要
本博文介绍的是,在完整配好SSM框架环境、搭建好整体项目架构以及完整配置了SSM相关配置文件的后续内容,主要是“Source Root”类型的java文件夹中的具体代码的分享,代码内容是实现信息全查~
文章目录
- 博客概要
- 1.项目环境配置+项目搭建+文件配置
- 2.编撰主体代码
- 2.1pojo
- 2.2dao
- 2.3service+impl
- 2.4controller
- 2.5mapper.xml配置
- 2.6JSP
- 2.7运行结果
1.项目环境配置+项目搭建+文件配置
看本博主其他博文内容啦,以下附上~
【*】SSM框架——项目搭建+相关文件配置
2.编撰主体代码
2.1pojo
具体代码
public class Paper {
private int pid;
private String pname;
private int pnum;
private String pdetail;
@Override
public String toString() {
return "Paper{" +
"pid=" + pid +
", pname='" + pname + ''' +
", pnum=" + pnum +
", pdetail='" + pdetail + ''' +
'}';
}
public Paper() {
}
public Paper(int pid, String pname, int pnum, String pdetail) {
this.pid = pid;
this.pname = pname;
this.pnum = pnum;
this.pdetail = pdetail;
}
public Paper(String pname, int pnum, String pdetail) {
this.pname = pname;
this.pnum = pnum;
this.pdetail = pdetail;
}
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public String getPname() {
return pname;
}
public void setPname(String pname) {
this.pname = pname;
}
public int getPnum() {
return pnum;
}
public void setPnum(int pnum) {
this.pnum = pnum;
}
public String getPdetail() {
return pdetail;
}
public void setPdetail(String pdetail) {
this.pdetail = pdetail;
}
}
2.2dao
具体代码
/**
* 数据持久层'
* jdbc注解
*/
@Component
public interface PaperDao {
/**
* 修改
* @param paper
* @return
*/
int UpdP(Paper paper);
/**
* 全查
* @return
*/
List<Paper> selByAllP();
}
2.3service+impl
具体代码
//service
/**
* service注解
*/
@Service
public interface PaperService {
/**
* 根据面向对象思维实现业务逻辑层
*/
/**
* 全查
* @return
*/
List<Paper> selByAllP();
}
//impl
@Service
public class PaperServiceImpl implements PaperService {
@Autowired
private PaperDao paperDao;
public void setPaperDao(PaperDao paperDao) {
this.paperDao = paperDao;
}
/**
* 全查
* @return
*/
@Override
public List<Paper> selByAllP() {
return paperDao.selByAllP();
}
}
2.4controller
具体代码
@Controller
@RequestMapping("/paper")
public class PaperCcontroller {
@Autowired
private PaperService paperService;
public void setPaperService(PaperService paperService) {
this.paperService = paperService;
}
/**
* 从index跳转至allPaper
* Model传参机制
*/
@RequestMapping("/allPaper")
public String toAllPaper(Model model) {
List<Paper> papers = paperService.selByAllP();
model.addAttribute("papers", papers);
return "allPaper";
}
}
2.5mapper.xml配置
具体代码
<?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">
<!--namespace(告诉Mybatis要做什么)-->
<mapper namespace="com.wcw.dao.PaperDao">
<!--
告诉Mybatis,返回值的样子-->
<resultMap id="paperResultMap" type="Paper">
<id property="pid" column="pId" />
<result property="pname" column="pName" />
<result property="pnum" column="pNum" />
<result property="pdetail" column="pDetail" />
</resultMap>
<!--
全查-->
<select id="selByAllP" resultMap="paperResultMap">
select * from tb_paper
</select>
</mapper>
2.6JSP
具体代码
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>论文编号</th>
<th>论文名字</th>
<th>论文数量</th>
<th>论文详情</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach var="paper" items="${requestScope.get('papers')}" varStatus="status">
<tr>
<td>${paper.pid}</td>
<td>${paper.pname}</td>
<td>${paper.pnum}</td>
<td>${paper.pdetail}</td>
<td>
<a href="${path}/paper/toUpdatePaper?id=${paper.pid}">更改</a>
<a href="<%=appPath%>/paper/del/${paper.pid}">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
2.7运行结果
最后
以上就是可爱芹菜为你收集整理的Spring+SpringMVC+Mybatis—信息全查的全部内容,希望文章能够帮你解决Spring+SpringMVC+Mybatis—信息全查所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复