(代碼裏面都有註釋)css
由於我這裏分了模塊,因此有父子級的共兩個pom文件java
父級:mysql
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>edu.nf</groupId> <artifactId>conformity</artifactId> <version>1.0-SNAPSHOT</version> <modules> <module>ch01</module> <module>ch02</module> <module>ch03</module> <module>ch04</module> <module>ch05</module> </modules> <packaging>pom</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> <!-- 版本管理 --> <spring.version>5.1.1.RELEASE</spring.version> <junit.version>4.12</junit.version> <druid.version>1.1.10</druid.version> <mysql.version>5.1.47</mysql.version> <mybatis.version>3.4.6</mybatis.version> <mybatis.spring.version>1.3.2</mybatis.spring.version> <pagehelper.version>5.1.2</pagehelper.version> <aspect.version>1.9.1</aspect.version> <servlet.version>4.0.1</servlet.version> <jackson.version>2.9.6</jackson.version> <slf4j.version>1.7.25</slf4j.version> </properties> <!-- 依賴管理,子模塊按需依賴 --> <dependencyManagement> <dependencies> <!-- javax.servlet-api --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${servlet.version}</version> <scope>provided</scope> </dependency> <!-- spring-web --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <!-- spring-webmvc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <!-- jackson-databind --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <!-- spring-jdbc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <!-- spring-tx --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <!-- mybatis--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <!-- mybatis整合spring插件 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis.spring.version}</version> </dependency> <!-- pagehelper分頁插件--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>${pagehelper.version}</version> </dependency> <!-- aspectjweaver--> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspect.version}</version> </dependency> </dependencies> </dependencyManagement> <!-- 公共依賴 --> <dependencies> <!-- spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <!-- slf4j-log4j12 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <!-- junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> </dependency> <!-- druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> </dependencies> </project>
子級:git
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>conformity</artifactId> <groupId>edu.nf</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>ch04</artifactId> <packaging>war</packaging> <dependencies> <!-- javax.servlet-api --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <!-- spring-webmvc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <!-- jackson --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <!-- mybatis整合spring插件 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <!-- 分頁插件--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> </dependency> <!-- spring-jdbc--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <!-- spring-tx--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> </dependency> <!-- aspectjweaver --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> </dependency> </dependencies> <!-- war插件 --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.2</version> <configuration> <warSourceDirectory>web</warSourceDirectory> <!-- 指定web.xml路徑 --> <webXml>web\WEB-INF\web.xml</webXml> </configuration> </plugin> </plugins> </build> </project>
ssm所需jar包:github
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <!-- 當初始化不一樣的配置文件時,spring會初始化不一樣的容器對象, 也就是會產生父子容器,子容器能夠共享父容器的內容,但父容器是不能 訪問子容器的對象--> <!-- 配置監聽器去初始化applicationContext.xml --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 配置監聽器的初始化參數--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 配置Spring提供的字符編碼過濾器 --> <filter> <filter-name>EncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <!-- 指定編碼 --> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <!-- 讓response的編碼和request保持一致--> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- WebStatFilter用於採集監控的數據--> <filter> <filter-name>DruidWebStatFilter</filter-name> <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class> <init-param> <param-name>exclusions</param-name> <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value> </init-param> </filter> <filter-mapping> <filter-name>DruidWebStatFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 配置StatViewServlet,用於啓用監控視圖 --> <servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> <init-param> <!-- 用戶名 --> <param-name>loginUsername</param-name> <param-value>root</param-value> </init-param> <init-param> <!-- 密碼 --> <param-name>loginPassword</param-name> <param-value>root</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping> <!-- 配置核心控制器 --> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 初始化mvc配置文件 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:dispatcher-servlet.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
建立Springmvc核心配置文件web
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 掃描相應的控制器組件,不包含Service以及Dao --> <context:component-scan base-package="edu.nf.ch04.controller"/> <!-- 啓用mvc註解驅動--> <mvc:annotation-driven/> <!-- 靜態資源處理--> <mvc:default-servlet-handler/> <!-- 配置視圖解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
建立Spring核心配置文件spring
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mybatis="http://mybatis.org/schema/mybatis-spring" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 啓用註解並掃描 --> <context:component-scan base-package="edu.nf.ch04"> <!-- 排除控制層組件,也就是排除帶有@Controller註解的類 --> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- 配置數據源鏈接池 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 數據庫鏈接屬性 --> <property name="url" value="jdbc:mysql://localhost:3306/homework?useSSL=true&useUnicode=true&characterEncoding=utf-8"/> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="username" value="root"/> <property name="password" value="root"/> <!-- 啓用系統監控過濾器 --> <property name="filters" value="stat"/> <!-- 最大鏈接池數量 --> <property name="maxActive" value="200"/> <!-- 初始化時創建物理鏈接的個數--> <property name="initialSize" value="5"/> <!-- 最小鏈接池數量--> <property name="minIdle" value="5"/> <!-- 獲取鏈接時最大等待時間,單位毫秒--> <property name="maxWait" value="60000"/> <!-- 銷燬線程會檢測鏈接的間隔時間,(單位毫秒) 若是鏈接空閒時間大於等於minEvictableIdleTimeMillis則關閉物理鏈接--> <property name="timeBetweenEvictionRunsMillis" value="60000"/> <!-- 鏈接保持空閒而不被驅逐的最小時間 --> <property name="minEvictableIdleTimeMillis" value="300000"/> <!--申請鏈接的時候檢測,若是空閒時間大於timeBetweenEvictionRunsMillis, 執行validationQuery檢測鏈接是否有效--> <property name="testWhileIdle" value="true"/> <!-- 申請鏈接時執行validationQuery檢測鏈接是否有效 --> <property name="testOnBorrow" value="false"/> <!-- 歸還鏈接時執行validationQuery檢測鏈接是否有效--> <property name="testOnReturn" value="false"/> <!-- 是否緩存preparedStatement, mysql建議關閉--> <property name="poolPreparedStatements" value="false"/> <!-- 僞SQL,用於檢查鏈接是否可用 --> <property name="validationQuery" value="select 1"/> </bean> <!-- 配置SqlSessionFactory,將mybatis的SqlSessionFactory交給Spring容器管理 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注入druid數據源 --> <property name="dataSource" ref="dataSource"/> <!-- 給實體包下的類定義默認別名--> <property name="typeAliasesPackage" value="edu.nf.ch04.entity"/> <!-- 指定mapper映射配置文件的目錄--> <property name="mapperLocations" value="classpath:mapper/*.xml"/> <!-- 配置分頁插件--> <property name="plugins"> <!-- 配置一個bean,指定分頁插件的攔截器--> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <!--配置攔截器的參數屬性 --> <props> <!-- 指定數據庫方言 --> <prop key="helperDialect">mysql</prop> <!-- 分頁參數使用註解支持--> <prop key="supportMethodsArguments">true</prop> </props> </property> </bean> </property> </bean> <!-- 指定掃描的dao接口的包,利用動態代理在運行時生成dao的實現類 --> <mybatis:scan base-package="edu.nf.ch04.dao"/> <!-- 裝配DataSource的事務管理器--> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 須要注入一個DataSource --> <property name="dataSource" ref="dataSource"/> </bean> <!-- 啓用事務註解驅動,transaction-manager引用上面定義的事務管理器的id, 若是id的名稱就叫作transactionManager,那麼就不須要指定這個屬性,由於是默認值--> <tx:annotation-driven transaction-manager="txManager"/> </beans>
mapper:ClassDao.xml 數據庫執行語句sql
<?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="edu.nf.ch04.dao.ClassDao"> <resultMap id="classMap" type="classInfo"> <id property="id" column="c_id"/> <result property="className" column="c_name"/> </resultMap> <select id="listClassInfo" resultMap="classMap"> select * from class_info </select> <select id="getClassById" parameterType="integer" resultMap="classMap"> select * from class_info where c_id = #{id} </select> <insert id="saveClassInfo" parameterType="classInfo"> insert into class_info(c_name) values(#{className}); </insert> <update id="updateClassInfo" parameterType="classInfo"> update class_info set c_name = #{className} </update> </mapper>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration> <!-- 指定日誌的輸出方式,ConsoleAppender表示輸出到控制檯 --> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <!-- 使用自定義佈局--> <layout class="org.apache.log4j.PatternLayout"> <!-- 自定義佈局轉換參數說明 %d 日期格式 %p 輸出級別 %t 輸出當先執行線程名 %M 輸出當先運行的方法名 %l 輸出日誌事件的發生位置,包括類名、發生的線程,以及在代碼中的行數 %c 輸出當前的類名 %m 輸出日誌內容 %n 換行--> <param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss} %-5p] [%t] %l - %m%n" /> </layout> <!-- 過濾輸出範圍--> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="levelMin" value="debug" /> <param name="levelMax" value="error" /> <param name="AcceptOnMatch" value="true" /> </filter> </appender> <!-- 配置log4j的root,默認全部日誌都將以root的配置進行輸出--> <root> <!-- 指定輸出級別,log4j一共分爲7個級別,由低到高分爲ALL、DEBUG、INFO、WARN、ERROR、FATAL、OFF 但官方建議使用DEBUG、INFO、WARN、ERROR這4個級別。經過使用日誌級別,能夠控制應用程序中相應級別日誌信息的輸出。 例如,若是使用了info級別,則應用程序中全部低於info級別的日誌信息(如debug)將不會被打印出來。--> <priority value ="debug"/> <!-- 引用輸出方式,ref對應appender的name --> <appender-ref ref="console"/> </root> </log4j:configuration>
BaseController:數據庫
package edu.nf.ch04.controller; import edu.nf.ch04.controller.vo.ResponseVO; /** * @author wangl * @date 2018/11/12 * 父級控制器 * 封裝了給子類調用的成功響應視圖的方法 */ public class BaseController { protected ResponseVO success(){ return new ResponseVO(); } protected ResponseVO success(Object value){ ResponseVO vo = new ResponseVO(); vo.setValue(value); return vo; } protected ResponseVO success(Integer code, Object value){ ResponseVO vo = new ResponseVO(); vo.setCode(code); vo.setValue(value); return vo; } }
ClassController:express
package edu.nf.ch04.controller; import edu.nf.ch04.controller.vo.ResponseVO; import edu.nf.ch04.entity.ClassInfo; import edu.nf.ch04.servie.ClassService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.List; /** * @author wangl * @date 2018/11/12 */ @Controller public class ClassController extends BaseController{ /** * 日誌對象 */ private static final Logger logger = LoggerFactory.getLogger(ClassController.class); /** * 注入對象 */ @Autowired private ClassService classService; @GetMapping("/listClassInfo") @ResponseBody public ResponseVO listClassInfo(Integer pageNum, Integer pageSize){ List<ClassInfo> list = classService.listClassInfo(pageNum, pageSize); logger.info("查詢用戶列表: " + list.size()); return success(list); } @PostMapping("/add") public ResponseVO addClass(ClassInfo classInfo){ classService.saveClassInfo(classInfo); return success(); } }
advice(GlobalExceptionHandler):異常處理類
package edu.nf.ch04.controller.advice; import edu.nf.ch04.controller.vo.ResponseVO; import edu.nf.ch04.servie.DataAccessException; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; /** * @author wangl * @date 2018/11/12 * 定義一個全局的異常處理類(相似一個切面) * 這個類中定義的全部方法都是異常處理方法, * 也能夠理解爲是全局的異常通知 * value屬性指定對哪些控制器進行切入攔截 */ @ControllerAdvice public class GlobalExceptionHandler { /** * 全局異常處理方法 * 用於處理參數異常 * @param e * @return */ @ExceptionHandler(DataAccessException.class) @ResponseBody public ResponseVO handleDataAccessException(DataAccessException e){ ResponseVO vo = new ResponseVO(); //設置相應狀態碼以及異常信息 vo.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value()); vo.setMessage(e.getMessage()); return vo; } }
vo響應視圖
package edu.nf.ch04.controller.vo; import org.springframework.http.HttpStatus; /** * @author wangl * @date 2018/11/12 * 響應視圖 */ public class ResponseVO { private Integer code = HttpStatus.OK.value(); private String message; private Object value; public Integer getCode() { return code; } public void setCode(Integer code) { this.code = code; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public Object getValue() { return value; } public void setValue(Object value) { this.value = value; } @Override public String toString() { return "ResponseVO{" + "code=" + code + ", message='" + message + '\'' + ", value=" + value + '}'; } }
自定義異常DataAccessException:
package edu.nf.ch04.servie; /** * @author wangl * @date 2018/11/12 */ public class DataAccessException extends RuntimeException{ public DataAccessException(String message) { super(message); } public DataAccessException(String message, Throwable cause) { super(message, cause); } public DataAccessException(Throwable cause) { super(cause); } }
業務層 接口ClassService
package edu.nf.ch04.servie; import edu.nf.ch04.entity.ClassInfo; import java.util.List; /** * @author wangl * @date 2018/11/8 */ public interface ClassService { /** * 查詢班級信息 * @param pageNum * @param pageSize * @return */ List<ClassInfo> listClassInfo(Integer pageNum, Integer pageSize); /** * 根據id查詢班級信息 * @param id * @return */ ClassInfo getClassById(Integer id); /** * 新建班級信息 * @param classInfo */ void saveClassInfo(ClassInfo classInfo); /** * 修改班級信息 * @param classInfo */ void updateClassInfo(ClassInfo classInfo); }
業務層 實現類ClassServiceImpl
package edu.nf.ch04.servie.impl; import edu.nf.ch04.dao.ClassDao; import edu.nf.ch04.entity.ClassInfo; import edu.nf.ch04.servie.ClassService; import edu.nf.ch04.servie.DataAccessException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.util.List; /** * @author wangl * @date 2018/11/8 * @Transactional 事務註解 */ @Service("classService") @Transactional(rollbackFor = RuntimeException.class) public class ClassServiceImpl implements ClassService { @Autowired private ClassDao classDao; @Transactional(rollbackFor = RuntimeException.class, propagation = Propagation.SUPPORTS, readOnly = true) @Override public List<ClassInfo> listClassInfo(Integer pageNum, Integer pageSize) { return classDao.listClassInfo(pageNum, pageSize); } @Transactional(rollbackFor = RuntimeException.class, propagation = Propagation.SUPPORTS, readOnly = true) @Override public ClassInfo getClassById(Integer id) { return classDao.getClassById(id); } @Override public void saveClassInfo(ClassInfo classInfo) { try { classDao.saveClassInfo(classInfo); } catch (RuntimeException e) { e.printStackTrace(); throw new DataAccessException("添加失敗"); } } @Override public void updateClassInfo(ClassInfo classInfo) { try { classDao.updateClassInfo(classInfo); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("修改失敗"); } } }
package edu.nf.ch04.dao; import edu.nf.ch04.entity.ClassInfo; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import java.util.List; /** * @author wangl * @date 2018/11/8 */ @Repository public interface ClassDao { /** * 查詢班級列表信息 * @param pageNum * @param pageSize * @return */ List<ClassInfo> listClassInfo(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize); /** * 根據id查詢班級信息 * @param id * @return */ ClassInfo getClassById(Integer id); /** * 新建班級信息 * @param classInfo */ void saveClassInfo(ClassInfo classInfo); /** * 修改班級信息 * @param classInfo */ void updateClassInfo(ClassInfo classInfo); }
package edu.nf.ch04.entity; /** * @author wangl * @date 2018/11/8 */ public class ClassInfo { private Integer id; private String className; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getClassName() { return className; } public void setClassName(String className) { this.className = className; } @Override public String toString() { return "ClassInfo{" + "id=" + id + ", className='" + className + '\'' + '}'; } }