5、Spring+Struts2+MyBatis+分页(mybatis无代理)增删改查
1、创建如下项目结构
2、在src下的com.entity包下创建Dept.java
package com.entity;
/**
* 部门表
* @author Holly老师
*
*/
public class Dept {
private Integer deptno; //部门编号
private String dname; //部门名称
private String loc; //位置 public Dept() {
} public Dept(Integer deptno, String dname, String loc) {
this.deptno = deptno;
this.dname = dname;
this.loc = loc;
} public Integer getDeptno() {
return deptno;
} public void setDeptno(Integer deptno) {
this.deptno = deptno;
} public String getDname() {
return dname;
} public void setDname(String dname) {
this.dname = dname;
} public String getLoc() {
return loc;
} public void setLoc(String loc) {
this.loc = loc;
} }
Dept.java
3、在src下的com.page包下创建Page.java
package com.page;
/**
*
* @author Holly老师
*
*/
public class Page {
private Integer pageno;
private Integer pagesize;
private Integer totalcount;
private Integer totalpage;
private Integer startrow;
private Integer endrow; public Page() {
}
public Page(Integer pageno, Integer pagesize, Integer totalcount) {
this.pageno = pageno;
this.pagesize = pagesize;
this.startrow=pageno*pagesize;
this.endrow=(pageno-1)*pagesize;
this.totalcount = totalcount;
this.setTotalpage(totalcount);
}
public Integer getPageno() {
return pageno;
}
public void setPageno(Integer pageno) {
this.pageno = pageno;
}
public Integer getPagesize() {
return pagesize;
}
public void setPagesize(Integer pagesize) {
this.pagesize = pagesize;
}
public Integer getTotalcount() {
return totalcount;
}
public void setTotalcount(Integer totalcount) {
this.totalcount = totalcount;
}
public Integer getTotalpage() {
return totalpage;
}
/**
* 总条数
* @param totalcount
*/
public void setTotalpage(Integer totalcount) {
this.totalpage = totalcount%pagesize==0? totalcount/pagesize:totalcount/pagesize+1;
}
public Integer getStartrow() {
return startrow;
}
public void setStartrow(Integer startrow) {
this.startrow = startrow;
}
public Integer getEndrow() {
return endrow;
}
public void setEndrow(Integer endrow) {
this.endrow = endrow;
} }
Page.java
4、在src下的com.mapper包下创建DeptMapper.java
package com.mapper; import java.util.List; import com.entity.Dept;
import com.page.Page; /**
* 数据访问层接口
* @author Holly老师
*
*/
public interface DeptMapper { //查询所有
public List<Dept> findAll();
//分页查询
public List<Dept> findPage(Page page);
//查询总记录数
public Integer findCount();
//根据id查询
public Dept findById(int id);
//保存对象
public int saveDept(Dept dept);
//修改对象
public int updateDept(Dept dept);
//根据id删除
public int deleteById(int id);
}
DeptMapper.java
5、在src下的com.mapper包下创建DeptMapper.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" >
<mapper namespace="com.mapper.DeptMapper">
<!-- 查询所有 -->
<select id="findAll" resultType="dept">
select * from dept
</select>
<!-- 分页查询 -->
<select id="findPage" resultType="dept" parameterType="page">
<![CDATA[
select * from
(
select rownum r,deptno,dname,loc from dept
where rownum<=#{startrow}
)d
where d.r> #{endrow}
]]>
</select>
<!-- 查询总记录数 -->
<select id="findCount" resultType="Integer">
select count(*) from dept
</select>
<!-- 根据id查询 -->
<select id="findById" parameterType="int" resultType="dept">
select * from dept where deptno=#{deptno}
</select>
<!-- 保存对象 -->
<insert id="saveDept" parameterType="dept">
insert into dept values(#{deptno},#{dname},#{loc})
</insert>
<!-- 修改对象 -->
<update id="updateDept" parameterType="dept">
update dept set dname=#{dname},loc=#{loc} where deptno=#{deptno}
</update>
<!-- 根据id删除 -->
<delete id="deleteById" parameterType="int">
delete from dept where deptno=#{deptno}
</delete> </mapper>
DeptMapper.xml
6、在src下创建mybatis-config.xml主配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd" >
<configuration>
<!-- 别名映射 -->
<typeAliases>
<typeAlias type="com.entity.Dept" alias="dept"/>
<typeAlias type="com.page.Page" alias="page"/>
</typeAliases>
<!-- 注册xml文件 -->
<mappers>
<mapper resource="com/mapper/DeptMapper.xml"/>
</mappers>
</configuration>
mybatis-config.xml
7、在src下创建log4j.properties日志属性文件
log4j.rootLogger=DEBUG, Console #Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.properties
8、在src下的com.mapper.impl包下创建DeptMapperImpl.java
package com.mapper.impl; import java.util.List; import org.mybatis.spring.SqlSessionTemplate; import com.entity.Dept;
import com.mapper.DeptMapper;
import com.page.Page;
/**
* 数据访问层接口的实现类
* @author Holly老师
*
*/
public class DeptMapperImpl implements DeptMapper {
//注入seqsession对象
private SqlSessionTemplate sqlSessionTemplate; //必须存在getter和setter否则xml文件不能注入,会报没有session
public SqlSessionTemplate getSqlSessionTemplate() {
return sqlSessionTemplate;
} public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
this.sqlSessionTemplate = sqlSessionTemplate;
}
/**
* 1.根据id删除
*/
public int deleteById(int id) {
int num=sqlSessionTemplate.delete("com.mapper.DeptMapper.deleteById", id);
if(num>0){
System.out.println("删除成功");
}else{
System.out.println("删除失败");
}
return num;
} /**
* 2.添加部门信息
*/
public int saveDept(Dept dept) {
int num=sqlSessionTemplate.insert("com.mapper.DeptMapper.saveDept", dept);
if(num>0){
System.out.println("添加成功");
}else{
System.out.println("添加失败");
}
return num;
}
/**
* 3.修改
*/
public int updateDept(Dept dept) {
int num=sqlSessionTemplate.update("com.mapper.DeptMapper.updateDept", dept);
if(num>0){
System.out.println("修改成功");
}else{
System.out.println("修改失败");
}
return num;
} /**
* 4.查询所有
*/
public List<Dept> findAll() {
List<Dept> list=sqlSessionTemplate.selectList("com.mapper.DeptMapper.findAll");
if(list!=null){
System.out.println("查到所有");
}else{
System.out.println("没有查到所有");
}
return list;
}
/**
* 5.根据id没有查到
*/
public Dept findById(int id) {
Dept dept=sqlSessionTemplate.selectOne("com.mapper.DeptMapper.findById",id);
if(dept!=null){
System.out.println("根据id查到");
}else{
System.out.println("根据id没有查到");
}
return dept;
}
/**
* 分页查询
*/
public List<Dept> findPage(Page page) {
List<Dept> list=sqlSessionTemplate.selectList("com.mapper.DeptMapper.findPage",page);
if(list!=null){
System.out.println("分页查到了");
}else{
System.out.println("分页没有查到");
}
return list;
}
/**
* 查询总记录数
*/
public Integer findCount() {
Integer totalCount=sqlSessionTemplate.selectOne("com.mapper.DeptMapper.findCount");
return totalCount;
} }
DeptMapperImpl.java
9、在src下的com.service包下创建DeptService.java
package com.service; import java.util.List; import com.entity.Dept;
import com.page.Page;
/**
* 业务逻辑层接口
* @author Holly老师
*
*/
public interface DeptService {
//查询所有
public List<Dept> findAll();
//分页查询
public List<Dept> findPage(Page page);
//查询总记录数
public Integer findCount();
//根据id查询
public Dept findById(int id);
//保存对象
public int saveDept(Dept dept);
//修改对象
public int updateDept(Dept dept);
//根据id删除
public int deleteById(int id); }
DeptService.java
10、在src下的com.service.impl包下创建DeptServiceImpl.java
package com.service.impl; import java.util.List; import com.entity.Dept;
import com.mapper.DeptMapper;
import com.page.Page;
import com.service.DeptService;
/**
* 业务逻辑层接口实现类
* @author Holly老师
*
*/
public class DeptServiceImpl implements DeptService {
//注入数据访问层对象
private DeptMapper dao;
//必须存在getter和setter,否则xml注入不了
public DeptMapper getDao() {
return dao;
} public void setDao(DeptMapper dao) {
this.dao = dao;
}
/**
* 1.删除
*/
public int deleteById(int id) {
return dao.deleteById(id);
}
/**
* 2.查询所有
*/
public List<Dept> findAll() {
return dao.findAll();
}
/**
* 3.根据id查询
*/
public Dept findById(int id) {
return dao.findById(id);
}
/**
* 4.保存对象
*/
public int saveDept(Dept dept) {
return dao.saveDept(dept);
}
/**
* 5.修改对象
*/
public int updateDept(Dept dept) {
return dao.updateDept(dept);
}
/**
* 6.分页查询
*/
public List<Dept> findPage(Page page) {
return dao.findPage(page);
}
/**
* 7.查询总记录数
*/
public Integer findCount() {
return dao.findCount();
} }
DeptServiceImpl.java
11、在src下的com.action包下创建DeptAction.java
package com.action; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import com.entity.Dept;
import com.opensymphony.xwork2.ActionSupport;
import com.page.Page;
import com.service.DeptService;
/**
*
* @author Holly老师
*
*/
public class DeptAction extends ActionSupport { //注入业务逻辑层对象
private DeptService service; //struts标签中动态代理赋值对象
private Dept dept; //分页对象
private Page page; /**
* 1.查询所有
* @return
*/
public String findAll(){
List<Dept> list=service.findAll();
if(list!=null){
HttpServletRequest request=ServletActionContext.getRequest();
request.setAttribute("list", list);
return SUCCESS;
}else{
return ERROR;
} } /**
* 1.分页查询所有
* @return
*/
public String findPage(){
//当前页
Integer pageNo=1;
if(page!=null){
System.out.println("page不为空");
pageNo=page.getPageno();
}else{
System.out.println("page为空");
}
//页面大小
Integer pageSize=3;
//查询总条数
Integer totalCount= service.findCount();
page=new Page(pageNo, pageSize, totalCount);
List<Dept> list=service.findPage(page);
if(list!=null){
HttpServletRequest request=ServletActionContext.getRequest();
request.setAttribute("list", list);
request.setAttribute("page", page);
return SUCCESS;
}else{
return ERROR;
} }
/**
* 根据id查询
* @return
*/
public String findById(){
if(dept!=null){
Dept dt=service.findById(dept.getDeptno());
if(dt!=null){
HttpServletRequest request=ServletActionContext.getRequest();
request.setAttribute("dt", dt);
return SUCCESS;
}
}
return ERROR; }
/**
* 添加
* @return
*/
public String save(){
if(dept!=null){
int num=service.saveDept(dept);
if(num>0){
return SUCCESS;
}else{
return ERROR;
}
}
return ERROR;
}
/**
* 修改
* @return
*/
public String update(){
if(dept!=null){
int num=service.updateDept(dept);
if(num>0){
return SUCCESS;
}else{
return ERROR;
}
}
return ERROR; }
/**
* 删除
* @return
*/
public String delete(){
if(dept!=null){
int num=service.deleteById(dept.getDeptno());
if(num>0){
return SUCCESS;
}else{
return ERROR;
}
}
return ERROR;
} public DeptService getService() {
return service;
} public void setService(DeptService service) {
this.service = service;
} public Dept getDept() {
return dept;
} public void setDept(Dept dept) {
this.dept = dept;
} public Page getPage() {
return page;
} public void setPage(Page page) {
this.page = page;
} }
DeptAction.java
12、在src下创建Spring的配置文件applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd ">
<!-- 1.数据源配置 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
<property name="username" value="scott"/>
<property name="password" value="tiger"/>
</bean> <!-- 2.配置事务 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 事务中注入数据源-->
<property name="dataSource" ref="dataSource"/>
</bean> <!-- 3.配置SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- 注入mybaits主配置文件 -->
<property name="configLocation">
<value>classpath:mybatis-config.xml</value>
</property>
</bean> <!-- 4.获取SqlSessionTemplate -->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<!--通过构造注入sqlsessionFactory-->
<!-- index表示构造的参数索引位置,type表示构造参数的类型-->
<constructor-arg index="0" ref="sqlSessionFactory"/>
</bean> <!-- 5.实例化dao -->
<bean id="dao" class="com.mapper.impl.DeptMapperImpl">
<!-- 注入sqlSessionTemplate -->
<property name="sqlSessionTemplate" ref="sqlSessionTemplate"/>
</bean> <!-- 6.实例化service -->
<bean id="service" class="com.service.impl.DeptServiceImpl">
<!-- 注入dao -->
<property name="dao" ref="dao"/>
</bean> <!-- 7.实例化action -->
<bean id="DeptAction" class="com.action.DeptAction">
<!-- 注入service -->
<property name="service" ref="service"/>
</bean> </beans>
applicationContext.xml
13、在src下创建Struts2的配置文件struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "struts-2.1.7.dtd" >
<struts>
<!-- 中文乱码处理 -->
<constant name="struts.i18n.encoding" value="UTF-8"/>
<package name="default" namespace="/" extends="struts-default">
<!-- 默认首起项配置 <default-action-ref name="findPage" />
-->
<!-- ssm框架集合时,class的值是spring配置文件的实例化action的bean的id值 -->
<!-- 1.查询所有 -->
<action name="findAll" class="DeptAction" method="findAll">
<result name="success">index.jsp</result>
<result name="error">fail.jsp</result>
</action> <!-- 1.查询所有 -->
<action name="findPage" class="DeptAction" method="findPage">
<result name="success">index.jsp</result>
<result name="error">fail.jsp</result>
</action> <!-- 2.根据id查询 -->
<action name="findById" class="DeptAction" method="findById">
<result name="success">update.jsp</result>
<!-- 重定向到action -->
<result name="error" type="redirectAction">findAll</result>
</action> <!-- 3.添加 -->
<action name="save" class="DeptAction" method="save">
<!-- 重定向到action -->
<result name="success" type="redirectAction">findAll</result>
<result name="error">insert.jsp</result>
</action> <!-- 4.修改 -->
<action name="update" class="DeptAction" method="update">
<!-- 重定向到action -->
<result name="success" type="redirectAction">findAll</result>
<result name="error">fail.jsp</result>
</action> <!-- 5.删除 -->
<action name="delete" class="DeptAction" method="delete">
<!-- 重定向到action -->
<result name="success" type="redirectAction">findAll</result>
<result name="error">fail.jsp</result>
</action> </package> </struts>
struts.xml
14、编辑WebRoot下的WEB-INF下web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list> </web-app>
web.xml
15、在WebRoot下创建index.jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<center>
<a href="insert.jsp">添加</a>
<table border="1">
<tr><td>部门编号</td><td>部门名称</td><td>部门地址</td><td>操作</td></tr>
<c:forEach var="i" items="${requestScope.list}">
<tr>
<td>${i.deptno}</td>
<td>${i.dname}</td>
<td>${i.loc}</td>
<td>
<a href="delete.action?dept.deptno=${i.deptno}">删除</a>
|
<a href="findById.action?dept.deptno=${i.deptno}">修改</a>
</td>
</tr>
</c:forEach>
</table>
第${page.pageno}/${page.totalpage }页
<a href="findPage.action?page.pageno=1">首页</a>
<c:choose>
<c:when test="${page.pageno>1}">
<a href="findPage.action?page.pageno=${page.pageno-1 }">上一页</a>
</c:when>
<c:otherwise>
<a href="javascript:alert('已经是第一页了!');">上一页</a> </c:otherwise>
</c:choose> <c:choose>
<c:when test="${page.pageno<page.totalpage}">
<a href="findPage.action?page.pageno=${page.pageno+1 }">下一页</a>
</c:when>
<c:otherwise>
<a href="javascript:alert('已经是最后一页了!');">上一页</a> </c:otherwise>
</c:choose>
<a href="findPage.action?page.pageno=${page.totalpage}">末页</a>
总${page.totalcount }条
</center>
</body>
</html>
index.jsp
16、在WebRoot下创建insert.jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<center>
<form action="save.action" method="post">
<table border="1">
<tr>
<td>部门编号:</td>
<td><input type="text" name="dept.deptno"/></td>
</tr>
<tr>
<td>部门名称:</td>
<td><input type="text" name="dept.dname"/></td>
</tr>
<tr>
<td>部门地址:</td>
<td><input type="text" name="dept.loc"/></td>
</tr>
<tr>
<td><input type="submit" value="提交"/></td>
<td><input type="reset" value="重置"/></td>
</tr>
</table>
</form>
</center>
</body>
</html>
insert.jsp
17、在WebRoot下创建update.jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<center>
<fieldset>
<legend>修改操作</legend>
<form action="update.action" method="post">
<table border="1">
<tr>
<td>部门编号:</td>
<td><input type="text" name="dept.deptno" value="${dt.deptno}" readonly="readonly"/></td>
</tr>
<tr>
<td>部门名称:</td>
<td><input type="text" name="dept.dname" value="${dt.dname}"/></td>
</tr>
<tr>
<td>部门地址:</td>
<td><input type="text" name="dept.loc" value="${dt.loc}"/></td>
</tr>
<tr>
<td><input type="submit" value="提交"/></td>
<td><input type="reset" value="重置"/></td>
</tr>
</table>
</form>
</fieldset> </center>
</body>
</html>
update.jsp
18、在WebRoot下创建fail.jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
操作失败
</body>
</html>
fail.jsp
19、运行项目如下
5、Spring+Struts2+MyBatis+分页(mybatis无代理)增删改查的更多相关文章
- SpringBoot+Mybatis+Maven+MySQL逆向工程实现增删改查
SpringBoot+Mybatis+MySQL+MAVEN逆向工程实现增删改查 这两天简单学习了下SpringBoot,发现这玩意配置起来是真的方便,相比于SpringMVC+Spring的配置简直 ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_3-2.使用Mybatis注解开发视频列表增删改查
笔记 2.使用Mybatis注解开发视频列表增删改查 讲解:使用Mybatis3.x注解方式 增删改查实操, 控制台打印sql语句 1.控制台打印sql语句 ...
- (一)Mybatis基本配置,Statement方式,动态代理增删改查
首先明白Mybatis是干什么的,之前使用jdbc操作数据库时候要写很多语句,获取光标,连接,获取具体对象进行相应操作,代码过于繁琐,所以现在有了Mybatis,它将这个操作整合在了一起,你不需要关心 ...
- Mybatis之基于XML的增删改查
这里先吐槽下,写的半天的东西,IE浏览器弹出调试窗口导致写的东西全部没保存,搞得我还要重新用谷歌写,思路全没了,fuck. 前面学习了下spring的DAO层,说起DAO层,那ORM肯定是少不了的,O ...
- SSM框架之MyBatis框架实现简单的增删改查
MyBatis框架介绍 MyBatis是一个优秀的数据持久层框架,在实体类和SQL语句之间建立映射关系是一种半自动化的ORM实现,其封装性要低于Hibernate,性能优越,并且小巧,简单易学,应用也 ...
- MyBatis之二:简单增删改查
这一篇在上一篇的基础上简单讲解如何进行增删改查操作. 一.在mybatis的配置文件conf.xml中注册xml与注解映射 <!-- 注册映射文件 --> <mappers> ...
- SSMybatis整合 --详细解读Mybatis对oracle数据库进行增删改查(一)
Mybatis是现在主流的持久化层框架,与Hibernate不同的是,它鼓励程序员使用原声SQL语句对数据库进行操作.因此提供了非常灵活的功能.特别是当数据库同时访问数过多,需要进行优化时,使用sql ...
- mybatis学习(五)——增删改查及自增主键的获取
一.mybatis的增删改查 1.修改hotelMapper接口 package com.pjf.mybatis.dao; import com.pjf.mybatis.po.Hotel; publi ...
- mybatis:开发环境搭建--增删改查--多表联合查询(多对一)
什么是mybatisMyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBatis使用简单的XML或 ...
- MyBatis操作数据库(基本增删改查)
一.准备所需工具(jar包和数据库驱动) 网上搜索下载就可以 二.新建一个Java project 1.将下载好的包导入项目中,build path 2.编写MyBatis配置文件:主要填写prope ...
随机推荐
- 关于对HandlerThread的了解
在Android中经常需要创建一个循环线程,有耗时操作时候,放到里面去操作,如果没有耗时操作,就让该线程处于等待,但是不要杀死它, 最好不要一旦有耗时任务,就立刻创建一个新线程,因为会有性能问题. H ...
- Long类型比较大小,long型和Long型区别
今天写代码发现发现本地程序是正常的,但是发送到测试环境就不正常了,本着对数据的怀疑态度链接了测试数据库,调试程序发现,确实是数据问题,然后数据出现在什么地方呢?才发现是在判断用户所属的teamGrou ...
- 2. SpringMVC 上传文件操作
1.创建java web项目:SpringMVCUploadDownFile 2.在项目的WebRoot下的WEB-INF的lib包下添加如下jar文件 com.springsource.com.mc ...
- linux下如何查询jdk安装路径
1:echo $JAVA_HOME 使用$JAVA_HOME的话能定位JDK的安装路径的前提是配置了环境变量$JAVA_HOME,否则如下所示,根本定位不到JDK的安装路径 [root@localho ...
- [kuangbin带你飞]专题六 最小生成树 POJ 2421 Constructing Roads
给一个n个点的完全图 再给你m条道路已经修好 问你还需要修多长的路才能让所有村子互通 将给的m个点的路重新加权值为零的边到边集里 然后求最小生成树 #include<cstdio> #in ...
- [MFC] 编辑框 EditControl 输入数字范围限制
在MFC中,项目需要对编辑框EditControl的数字输入范围进行限制,主要有以下实现方式,各有优缺点,个人推荐第三种. 第一种:添加变量 为编辑框添加int.float变量的时候,可以填写最大值与 ...
- jquery css hover
<script type="text/javascript"> $(function () { $("#<%=btnSubmit.ClientID%&g ...
- js 设计模式-接口
js模拟java接口检测函数:确保子类实现接口中的方法:(出自js设计模式) 上代码: <script type="text/javascript" > <%-- ...
- PHP基础语法思维导图
- android之控件与布局
基本控件:TextViewButtonEditTextImageViewAlertDialog.BubliderProgressDialog 四种基本布局的特殊属性: LinerLayout andr ...