完整项目链接
https://github.com/LZX842056112/SSMPermission
<?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>org.example</groupId>
<artifactId>SSMPermission</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<properties>
<spring.version>5.0.2.RELEASE</spring.version>
<slf4j.version>1.6.6</slf4j.version>
<log4j.version>1.2.12</log4j.version>
<mysql.version>5.1.6</mysql.version>
<mybatis.version>3.4.5</mybatis.version>
<spring.security.version>5.0.1.RELEASE</spring.security.version>
</properties>
<dependencies>
<!-- spring -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- log start -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- log end -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<modules>
<module>ssm_dao</module>
<module>ssm_domain</module>
<module>ssm_service</module>
<module>ssm_utils</module>
<module>ssm_web</module>
</modules>
</project>
<?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/maven-v4_0_0.xsd">
<parent>
<artifactId>SSMPermission</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ssm_web</artifactId>
<packaging>war</packaging>
<name>ssm_web Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>ssm_service</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>ssm_web</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8888</port>
</configuration>
<version>2.2</version>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--只扫描web的注解-->
<context:component-scan base-package="com.itheima.web"></context:component-scan>
<!--视图解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!--不过滤资源-->
<mvc:resources mapping="/css/**" location="/css/"></mvc:resources>
<mvc:resources mapping="/img/**" location="/img/"></mvc:resources>
<mvc:resources mapping="/plugins/**" location="/plugins/"></mvc:resources>
<!--支持mvc注解(Controller中可以使用MVC的各种注解)-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--切面AOP,默认使用cglib的方式-->
<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>
</beans>
<?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:aop="http://www.springframework.org/schema/aop"
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://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--只扫描dao,service注解-->
<context:component-scan base-package="com.itheima.service"></context:component-scan>
<context:component-scan base-package="com.itheima.dao"></context:component-scan>
<!--导入db.properties-->
<context:property-placeholder location="classpath*:db.properties"></context:property-placeholder>
<!--数据库连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!--扫描dao接口-->
<bean id="configurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.itheima.dao"></property>
</bean>
<!--sqlSessionFactory工厂-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--支持事务注解的(@Transactional),transactionManager是指定的事务管理器-->
<tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!--配置加载类路径的配置文件-->
<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>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!--前端控制器-->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置初始化参数,创建完DispatcherServlet对象,加载springmvc.xml配置文件 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<!-- 服务器启动的时候,让DispatcherServlet对象创建 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!--中文乱码-->
<filter>
<filter-name>characterEncodingFilter</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>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*
index.html
index.htm
index.jsp
defult.html
defult.htm
defult.jsp
把资源路径(. . /)改成${pageContext.request.contextPath}/,获取webapp目录下的资源
昨天把(. . /)替换成${pageContext.request.contextPath}/时忘记写"/",导致页面没有画面
在domain,dao,service的pom.xml配置ssm_utils
报了个错
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
@Service
@Transactional
public class IProductServiceImpl implements IProductService {
@Autowired
private IProductDao productDao;
/**
* 根据productNum查询产品信息
* @param productNum
* @return
* @throws Exception
*/
@Override
public Product findByNum(String productNum) throws Exception {
if (productNum != null){
Product product = productDao.findByNum(productNum);
if (product != null){
return product;
}
}
return null;
}
/**
* 添加产品信息
* @param product
* @throws Exception
*/
@Override
public void addProduct(Product product) throws Exception {
productDao.addProduct(product);
}
<!--label显示的内容-->
<div class="tab-pane active" id="tab-label">
<form action="${pageContext.request.contextPath}/product/addProduct.do" method="post">
<div class="row data-type">
<div class="col-md-2 title">产品编号</div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="productNum"/>
</div>
<div class="col-md-2 title">出发时间</div>
<div class="col-md-4 data">
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right" id="dateTimePicker">
</div>
</div>
<div class="col-md-2 title">产品名称</div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="productName"/>
</div>
<div class="col-md-2 title">出发城市</div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="cityName"/>
</div>
<div class="col-md-2 title">产品价格</div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="productPrice"/>
</div>
<div class="col-md-2 title">状态</div>
<div class="col-md-4 data">
<div class="form-group form-inline">
<div class="radio"><label><input type="radio" name="productStatus" value="1"> 开启</label></div>
<div class="radio"><label><input type="radio" name="productStatus" value="0"> 关闭</label></div>
</div>
</div>
<div class="col-md-2 title rowHeight2x">产品描述</div>
<div class="col-md-10 data rowHeight2x">
<textarea class="form-control" rows="3" name="productDesc"></textarea>
</div>
<div class="col-md-12 data text-center">
<button type="button" class="btn bg-maroon">保存</button>
<button type="button" class="btn bg-default" onclick="history.back(-1);">返回</button>
</div>
</div>
</form>
</div>
<!--label显示的内容/-->
@Controller
@RequestMapping("/product")
public class ProductController {
@Autowired
IProductService productService;
/**
* 查询全部产品信息
* @return
* @throws Exception
*/
@RequestMapping("/findAll.do")
public ModelAndView findAll(@RequestParam(value = "page",defaultValue = "1",required = false)Integer page,@RequestParam(value = "size",defaultValue = "4",required = false) Integer size) throws Exception{
ModelAndView mv = new ModelAndView();
List<Product> productList = productService.findAll(page.intValue(),size.intValue());
PageInfo pageInfo = new PageInfo(productList);
mv.addObject("productList",productList);
mv.addObject("pageInfo",pageInfo);
mv.setViewName("product-list");
return mv;
}
}
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'IProductServiceImpl': Unsatisfied dependency expressed through field 'productDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'IProductDao' defined in URL [jar:file:/D:/apache-maven-3.6.1/respository/org/example/ssm_dao/1.0-SNAPSHOT/ssm_dao-1.0-SNAPSHOT.jar!/com/itheima/dao/IProductDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:/D:/ideaPage/SSMPermission/ssm_web/target/classes/applicationContext.xml]: Cannot create inner bean 'com.github.pagehelper.PageInterceptor#6c0b0092' of type [com.github.pagehelper.PageInterceptor] while setting bean property 'plugins' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.pagehelper.PageInterceptor#6c0b0092' defined in URL [file:/D:/ideaPage/SSMPermission/ssm_web/target/classes/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'properties' threw exception; nested exception is com.github.pagehelper.PageException: java.lang.ClassNotFoundException: mysql
dialect改成helperDialect
把db的信息又改成原来的,clean和重启后居然也能启动了,那第二天的报错就感觉挺迷的
<!-- .box-footer-->
<div class="box-footer">
<div class="pull-left">
<div class="form-group form-inline">
总共${pageInfo.pages}页,共${pageInfo.total}条数据。 每页
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select> 条
</div>
</div>
<div class="box-tools pull-right">
<ul class="pagination">
<li>
<a href="${pageContext.request.contextPath}/product/findAll.do?page=1&size=${pageInfo.pageSize}" aria-label="Previous">首页</a>
</li>
<li><a href="${pageContext.request.contextPath}/product/findAll.do?page=${pageInfo.prePage}&size=${pageInfo.pageSize}">上一页</a></li>
<c:forEach begin="1" end="${pageInfo.pages}" var="item">
<li><a href="${pageContext.request.contextPath}/product/findAll.do?page=${item}&size=${pageInfo.pageSize}">${item}</a></li>
</c:forEach>
<li><a href="${pageContext.request.contextPath}/product/findAll.do?page=${pageInfo.nextPage}&size=${pageInfo.pageSize}">下一页</a></li>
<li>
<a href="${pageContext.request.contextPath}/product/findAll.do?page=${pageInfo.pages}&size=${pageInfo.pageSize}" aria-label="Next">尾页</a>
</li>
</ul>
</div>
</div>
<!-- /.box-footer-->
<!--label显示的内容-->
<div class="tab-pane active" id="tab-label">
<form action="${pageContext.request.contextPath}/product/updateProduct.do" method="post">
<input type="hidden" class="form-control" name="id" value="${productById.id}"/>
<div class="row data-type">
<div class="col-md-2 title">产品编号</div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="productNum" value="${productById.productNum}"/>
</div>
<div class="col-md-2 title">出发时间</div>
<div class="col-md-4 data">
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right" id="dateTimePicker" value="${productById.departureTimeStr}">
</div>
</div>
<div class="col-md-2 title">产品名称</div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="productName" value="${productById.productName}"/>
</div>
<div class="col-md-2 title">出发城市</div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="cityName" value="${productById.cityName}"/>
</div>
<div class="col-md-2 title">产品价格</div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="productPrice" value="${productById.productPrice}"/>
</div>
<div class="col-md-2 title">状态</div>
<div class="col-md-4 data">
<div class="form-group form-inline">
<div class="radio"><label><input type="radio" name="productStatus" value="1" <c:if test="${productById.productStatus==1}">checked="checked"</c:if>> 开启</label></div>
<div class="radio"><label><input type="radio" name="productStatus" value="0" <c:if test="${productById.productStatus==0}">checked="checked"</c:if>> 关闭</label></div>
</div>
</div>
<div class="col-md-2 title rowHeight2x">产品描述</div>
<div class="col-md-10 data rowHeight2x">
<textarea class="form-control" rows="3" name="productDesc">${productById.productDesc}</textarea>
</div>
<div class="col-md-12 data text-center">
<button type="submit" class="btn bg-maroon">保存</button>
<button type="button" class="btn bg-default" onclick="history.back(-1);">返回</button>
</div>
</div>
</form>
</div>
<!--label显示的内容/-->
<!--修改产品信息-->
<update id="updateProduct" parameterType="com.itheima.domain.Product">
update product
set productNum=#{productNum},productName=#{productName},cityName=#{cityName},departureTime=#{departureTime},productPrice=#{productPrice},productDesc=#{productDesc},productStatus=#{productStatus}
where id=#{id}
</update>
/**
* 查询全部产品信息,模糊查询
* @param page
* @param size
* @param fuzzyName
* @return
* @throws Exception
*/
@RequestMapping("/findAll.do")
public ModelAndView findAll(@RequestParam(value = "page",defaultValue = "1")Integer page, @RequestParam(value = "size",defaultValue = "4") Integer size, @RequestParam(value = "fuzzyName",defaultValue = "",required = false) String fuzzyName) throws Exception{
ModelAndView mv = new ModelAndView();
//判断是乱码 (GBK包含全部中文字符;UTF-8则包含全世界所有国家需要用到的字符。)
if (!(Charset.forName("GBK").newEncoder().canEncode(fuzzyName))) {
//转码UTF8
fuzzyName = new String(fuzzyName.getBytes("ISO-8859-1"), "utf-8");
}
List<Product> productList = productService.findAll(page,size,fuzzyName);
PageInfo pageInfo = new PageInfo(productList);
mv.addObject("productList",productList);
mv.addObject("fuzzyName",fuzzyName);
mv.addObject("pageInfo",pageInfo);
mv.setViewName("product-list");
return mv;
}
参数前加@Param注解,防止parameterType的值出现错误
@Controller
@RequestMapping("/orders")
public class OrdersController {
@Autowired
IOrdersService ordersService;
/**
* 查询订单全部信息,模糊查询
* @param page
* @param size
* @param fuzzyName
* @return
* @throws Exception
*/
@RequestMapping(value = "/findAll.do",produces = "text/html;charset=UTF-8")
public ModelAndView findAll(@RequestParam(value = "page",defaultValue = "1",required = false) String page,@RequestParam(value = "size",defaultValue = "4",required = false) String size,@RequestParam(value = "fuzzyName",defaultValue = "",required = false) String fuzzyName) throws Exception {
ModelAndView mv = new ModelAndView();
//判断是乱码 (GBK包含全部中文字符;UTF-8则包含全世界所有国家需要用到的字符。)
if (!(Charset.forName("GBK").newEncoder().canEncode(fuzzyName))) {
//转码UTF8
fuzzyName = new String(fuzzyName.getBytes("ISO-8859-1"), "utf-8");
}
List<Orders> ordersList = ordersService.findAll(Integer.parseInt(page), Integer.parseInt(size),fuzzyName);
PageInfo pageInfo = new PageInfo(ordersList);
mv.addObject("ordersList",ordersList);
mv.addObject("fuzzyName",fuzzyName);
mv.addObject("pageInfo",pageInfo);
mv.setViewName("orders-list");
return mv;
}
}
<?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.itheima.dao.IOrdersDao">
<resultMap id="orderMap" type="com.itheima.domain.Orders">
<id column="id" property="id"></id>
<result column="orderNum" property="orderNum"></result>
<result column="orderTime" property="orderTime"></result>
<result column="peopleCount" property="peopleCount"></result>
<result column="orderDesc" property="orderDesc"></result>
<result column="payType" property="payType"></result>
<result column="orderStatus" property="orderStatus"></result>
<association column="productId" property="product" javaType="com.itheima.domain.Product">
<id column="id" property="id"></id>
<result column="productNum" property="productNum"></result>
<result column="productName" property="productName"></result>
<result column="cityName" property="cityName"></result>
<result column="departureTime" property="departureTime"></result>
<result column="productPrice" property="productPrice"></result>
<result column="productDesc" property="productDesc"></result>
<result column="productStatus" property="productStatus"></result>
</association>
<association column="memberId" property="member" javaType="com.itheima.domain.Member">
<id column="id" property="id"></id>
<result column="name" property="name"></result>
<result column="nickname" property="nickname"></result>
<result column="phoneNum" property="phoneNum"></result>
<result column="email" property="email"></result>
</association>
</resultMap>
<select id="findAll" parameterType="java.lang.String" resultType="com.itheima.domain.Orders" resultMap="orderMap">
select
o.id,o.orderNum,o.orderTime,o.peopleCount,o.orderDesc,o.payType,o.orderStatus,m.name,p.productName
from orders o
left join product p on o.productId=p.id
left join member m on o.memberId=m.id
<where>
1=1
<if test="fuzzyName!=null and fuzzyName!=''">
and productName like concat('%',#{fuzzyName},'%')
</if>
</where>
</select>
</mapper>
<!--数据列表-->
<table id="dataList" class="table table-bordered table-striped table-hover dataTable">
<thead>
<tr>
<th class="" style="padding-right:0px;">
<input id="selall" type="checkbox" class="icheckbox_square-blue">
</th>
<th>订单ID</th>
<th>订单编号</th>
<th>产品名称</th>
<th>下单时间</th>
<th>会员姓名</th>
<th>出行人数</th>
<th>支付方式</th>
<th>订单状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${ordersList}" var="order">
<tr>
<td><input value="${order.id}" name="ids" type="checkbox"></td>
<td>${order.id}</td>
<td>${order.orderNum}</td>
<td>${order.product.productName}</td>
<td>${order.orderTimeStr}</td>
<td>${order.member.name}</td>
<td>${order.peopleCount}</td>
<td>${order.payTypeStr}</td>
<td>${order.orderStatusStr}</td>
<td class="text-center">
<a href="${pageContext.request.contextPath}/orders/findById.do?id=${order.id}" class="btn bg-olive btn-xs">详情</a>
<a href="${pageContext.request.contextPath}/orders/findById.do?id=${order.id}" class="btn bg-olive btn-xs">编辑</a>
<a onclick="delById('${order.id}')" class="btn bg-olive btn-xs">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<!--数据列表/-->
<!--label显示的内容-->
<div class="tab-pane active" id="tab-label">
<form action="${pageContext.request.contextPath}/orders/addOrders.do" method="post">
<div class="row data-type">
<div class="col-md-2 title">订单编号</div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="orderNum"/>
</div>
<div class="col-md-2 title">下单时间</div>
<div class="col-md-4 data">
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right" name="orderTime" id="dateTimePicker">
</div>
</div>
<div class="col-md-2 title">出行人数</div>
<div class="col-md-4 data">
<input type="text" class="form-control" name="peopleCount"/>
</div>
<div class="col-md-2 title">产品名称</div>
<div class="col-md-4 data">
<select name="productId" class="form-control" style="width: 100%;">
<c:forEach items="${productList}" var="product">
<option value="${product.id}">${product.productName}</option>
</c:forEach>
</select>
</div>
<div class="col-md-2 title">会员信息</div>
<div class="col-md-4 data">
<select name="memberId" class="form-control" style="width: 100%;">
<c:forEach items="${memberList}" var="member">
<option value="${member.id}">${member.name}</option>
</c:forEach>
</select>
</div>
<div class="col-md-2 title">订单状态</div>
<div class="col-md-4 data">
<div class="form-group form-inline">
<div class="radio"><label><input type="radio" name="orderStatus" value="0"> 未支付</label></div>
<div class="radio"><label><input type="radio" name="orderStatus" value="1"> 已支付</label></div>
</div>
</div>
<div class="col-md-2 title">支付方式</div>
<div class="col-md-4 data">
<div class="form-group form-inline">
<div class="radio"><label><input type="radio" name="payType" value="0"> 支付宝</label></div>
<div class="radio"><label><input type="radio" name="payType" value="1"> 微信</label></div>
<div class="radio"><label><input type="radio" name="payType" value="2"> 其他</label></div>
</div>
</div>
<div class="col-md-2 title rowHeight2x">订单描述</div>
<div class="col-md-4 data rowHeight2x">
<textarea class="form-control" rows="3" name="orderDesc"></textarea>
</div>
<div class="col-md-12 data text-center">
<button type="submit" class="btn bg-maroon">添加</button>
<button type="button" class="btn bg-default" onclick="history.back(-1);">返回</button>
</div>
</div>
</form>
</div>
<!--label显示的内容/-->
/**
* 订单添加
* @param orders
* @return
* @throws Exception
*/
@RequestMapping("/addOrders.do")
public String addOrders(Orders orders,@RequestParam(name = "productId",required = true) String productId,@RequestParam(name = "memberId", required = true) String memberId) throws Exception {
if (orders.getOrderNum() != null && orders.getOrderNum() != "" && orders.getOrderNum().length() > 0){
String orderNum = ordersService.findByNum(orders.getOrderNum());
if (orderNum == null){
Product product = productService.findById(productId);
Member member = memberService.findById(memberId);
orders.setProduct(product);
orders.setMember(member);
ordersService.addOrders(orders);
}
}
return "redirect:findAll.do";
}