線纜庫存管理程序

前言:

    朋友是作線纜生意的,想要一個進銷存管理可是網上的現成的不太試用,功能太多操做繁瑣,對於以米爲單位的線纜,庫存不能簡單的加減。須要定製一個功能精簡的進銷存。html

    項目源碼地址:https://github.com/Gengry/zlxsC前端

    數據庫文件在data目錄下,最新的導入便可12開頭的是17年的文件,01開頭的是18年的當時只是用月日標識沒有加年。java

技術選型:

    以前用過一點spring boot可是項目不是本身搭建的,最近在看spring boot就用他吧。前端試用的zheng admin ui(https://github.com/shuzheng/zhengAdmin)是基於bootstarp的,函數庫Jquery,數據表格 bootstrap table,select2,jquery-confirm,zheng common的baseservice,mybatis,mybatis generator, druid,mysql,maven。mysql

    spring boot集成druid文檔(https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter)。我並無使用spring boot druid starter,而且關閉了spring boot datasource auto configuration。jquery

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

配置datasource。git

package com.zhonglianxs.erp.cpw.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInterceptor;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Properties;

//生命爲java配置類
@Configuration
//開啓spring事物支持
@EnableTransactionManagement
//配置mybatis mapper掃描
@MapperScan(value = "com.zhonglianxs.erp.cpw.mapper")
public class DataBaseConfiguration implements EnvironmentAware{

    private Environment environment;
    private RelaxedPropertyResolver propertyResolver;
    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
        this.propertyResolver = new RelaxedPropertyResolver(environment,"spring.datasource.");
    }

    //配置druidDataSource
    @Bean(name = "druidDataSource" ,initMethod = "init",destroyMethod = "close")
    public DruidDataSource dataSource(){
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName(propertyResolver.getProperty("driverClassName"));
        druidDataSource.setUrl(propertyResolver.getProperty("url"));
        druidDataSource.setUsername(propertyResolver.getProperty("username"));
        druidDataSource.setPassword(propertyResolver.getProperty("password"));
        druidDataSource.setMaxActive(20);
        druidDataSource.setInitialSize(1);
        druidDataSource.setMaxWait(60000);
        druidDataSource.setTimeBetweenEvictionRunsMillis(60000);
        druidDataSource.setMinEvictableIdleTimeMillis(300000);
        druidDataSource.setTestWhileIdle(true);
        druidDataSource.setTestOnBorrow(false);
        druidDataSource.setTestOnReturn(false);
        druidDataSource.setPoolPreparedStatements(true);
        druidDataSource.setMaxOpenPreparedStatements(20);
        druidDataSource.setValidationQuery("SELECT 'x'");
        return druidDataSource;
    }

    //配置mybatis sqlsessionFactory
    @Bean public SqlSessionFactory sqlSessionFactory(@Qualifier("druidDataSource") DataSource dataSource) throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        //配置mybatis分頁插件
        Properties props = new Properties();
        props.setProperty("offsetAsPageNum", "false");
        props.setProperty("rowBoundsWithCount", "true");
        props.setProperty("pageSizeZero", "false");
        props.setProperty("reasonable", "false");
        props.setProperty("params", "pageNum=pageNum;pageSize=pageSize;count=countSql;reasonable=reasonable;pageSizeZero=pageSizeZero");
        props.setProperty("supportMethodsArguments","false");
        props.setProperty("autoRuntimeDialect","true");

        PageInterceptor pageInterceptor = new PageInterceptor();
        pageInterceptor.setProperties(props);
        sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageInterceptor});
        //配置mybatis xml文件路徑
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath*:com/zhonglianxs/erp/cpw/mapping/*.xml"));
        return sqlSessionFactoryBean.getObject();
    }
    
    //配置spring 事物管理器
    @Bean public PlatformTransactionManager transactionManager() throws SQLException {
        return new DataSourceTransactionManager(dataSource());
    }

}

發現啓動後獲取不到mybatis中的定義的方法,查了查都是說mapper名字和xml名字定義不一致什麼的,可是檢查後發現是一致的,maven package後打開打包文件,發現其中沒有resource目錄下的xml文件。應該是maven配置問題。參考https://www.cnblogs.com/pixy/p/4798089.htmlgithub

對pom.xml加入以下配置spring

<resources>
            <resource>
                <directory>src/main/resources</directory>
				<includes>
					<include>**/*.properties</include>
					<include>**/*.xml</include>
					<include>**/**</include>
				</includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>

配置spring mvc messageConConverter(https://my.oschina.net/u/3714931/blog/1594680)。sql

配置 jsp,一開始若是不部署在tomcat下解析不了jsp,由於spring boot沒有自動集成解析jsp的包。參考http://tengj.top/2017/03/13/springboot5/數據庫

pom.xml文件中配置

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.tomcat.embed</groupId>
			<artifactId>tomcat-embed-jasper</artifactId>
			<!--<scope>provided</scope>-->
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>

配置jsp開發模式不須要重啓直接生效

server.jsp-servlet.init-parameters.development=true

沒有作權限控制。

界面效果:

    

 

相關文章
相關標籤/搜索