框架作业0716

作业一

在这里插入图片描述
1.创建工程,导入相关的jar包
2.创建pojo包

Provider.java
package com.openlab.pojo;

import java.util.Date;

public class Provider {
    private Integer id;
    private String proCode;
    private String proName;
    private String proDesc;
    private String proContact;
    private String proPhone;
    private String proAddress;
    private String proFax;
    private Integer createdBy;
    private Date creationDate;
    private Date modifyDate;
    private Integer modifyBy;
    private String companyLicPicPath;
    private String orgCodePicPath;
    
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getProCode() {
        return proCode;
    }

    public void setProCode(String proCode) {
        this.proCode = proCode;
    }

    public String getProName() {
        return proName;
    }

    public void setProName(String proName) {
        this.proName = proName;
    }

    public String getProDesc() {
        return proDesc;
    }

    public void setProDesc(String proDesc) {
        this.proDesc = proDesc;
    }

    public String getProContact() {
        return proContact;
    }

    public void setProContact(String proContact) {
        this.proContact = proContact;
    }

    public String getProPhone() {
        return proPhone;
    }

    public void setProPhone(String proPhone) {
        this.proPhone = proPhone;
    }

    public String getProAddress() {
        return proAddress;
    }

    public void setProAddress(String proAddress) {
        this.proAddress = proAddress;
    }

    public String getProFax() {
        return proFax;
    }

    public void setProFax(String proFax) {
        this.proFax = proFax;
    }

    public Integer getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(Integer createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }

    public Integer getModifyBy() {
        return modifyBy;
    }

    public void setModifyBy(Integer modifyBy) {
        this.modifyBy = modifyBy;
    }

    public String getCompanyLicPicPath() {
        return companyLicPicPath;
    }

    public void setCompanyLicPicPath(String companyLicPicPath) {
        this.companyLicPicPath = companyLicPicPath;
    }

    public String getOrgCodePicPath() {
        return orgCodePicPath;
    }

    public void setOrgCodePicPath(String orgCodePicPath) {
        this.orgCodePicPath = orgCodePicPath;
    }
 @Override
    public String toString() {
        return "Provider{" +
                "id=" + id +
                ", proCode='" + proCode + '\'' +
                ", proName='" + proName + '\'' +
                ", proDesc='" + proDesc + '\'' +
                ", proContact='" + proContact + '\'' +
                ", proPhone='" + proPhone + '\'' +
                ", proAddress='" + proAddress + '\'' +
                ", proFax='" + proFax + '\'' +
                ", createdBy=" + createdBy +
                ", creationDate=" + creationDate +
                ", modifyDate=" + modifyDate +
                ", modifyBy=" + modifyBy +
                ", companyLicPicPath='" + companyLicPicPath + '\'' +
                ", orgCodePicPath='" + orgCodePicPath + '\'' +
                '}';
    }
}

3.配置mybatis-config配置文件

<?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>
        <package name="com.openlab.pojo"></package>
    </typeAliases>
    
</configuration>

4.创建dao包

ProviderDao.java

package com.openlab.dao;
import com.openlab.pojo.Provider;
import java.util.List;

public interface ProviderDao {

    List<Provider> selectAllProvider();
}

ProviderMapper.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.openlab.dao.ProviderDao">

    <select id="selectAllProvider" resultType="Provider">
        select * from smbms_provider
    </select>

</mapper>

5.创建dao.impl包

ProviderDaoImpl.java

package com.openlab.dao.impl;
import com.openlab.dao.ProviderDao;
import com.openlab.pojo.Provider;
import org.mybatis.spring.SqlSessionTemplate;

import java.util.List;

public class ProviderDaoImpl implements ProviderDao {

    private SqlSessionTemplate sqlSessionTemplate;

    public SqlSessionTemplate getSqlSessionTemplate() {
        return sqlSessionTemplate;
    }

    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    @Override
    public List<Provider> selectAllProvider() {
        return sqlSessionTemplate.selectList("com.openlab.dao.ProviderDao.selectAllProvider");
    }
}

6.创建service包
ProviderService.java

package com.openlab.service;
import com.openlab.pojo.Provider;
import java.util.List;

public interface ProviderService {

    List<Provider> getAllProvider();
}

7.创建service.impl包
ProviderServiceImpl.java

package com.openlab.service.impl;
import com.openlab.dao.ProviderDao;
import com.openlab.pojo.Provider;
import com.openlab.service.ProviderService;

import java.util.List;

public class ProviderServiceImpl implements ProviderService {

    private ProviderDao providerDao;

    public ProviderDao getProviderDao() {
        return providerDao;
    }

    public void setProviderDao(ProviderDao providerDao) {
        this.providerDao = providerDao;
    }

    @Override
    public List<Provider> getAllProvider() {
        return providerDao.selectAllProvider();
    }
}

8.配置applicationContext.xml文件

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url"
                  value="jdbc:mysql://127.0.0.1:3306/smbms?useUnicode=true&amp;characterEncoding=utf-8"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <property name="mapperLocations" value="classpath:com/openlab/dao/**/*.xml"/>
    </bean>

    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>
    </bean>

    <bean id="providerDao" class="com.openlab.dao.impl.ProviderDaoImpl">
        <property name="sqlSessionTemplate" ref="sqlSessionTemplate"></property>
    </bean>

    <bean id="providerService" class="com.openlab.service.impl.ProviderServiceImpl">
        <property name="providerDao" ref="providerDao"></property>
    </bean>
</beans>

9.测试

package com.openlab.test;
import com.openlab.pojo.Provider;
import com.openlab.service.ProviderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class Test01 {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        ProviderService providerService = (ProviderService) ac.getBean("providerService");
        List<Provider> allProvider = providerService.getAllProvider();
        for(Provider provider : allProvider){
            System.out.println(provider);
        }
    }
}

作业二

在这里插入图片描述

1.创建工程,导入相关的jar包
2.创建pojo包

Bill.java

package com.openlab.pojo;

import java.util.Date;

public class Bill {

    private int id;
    private String billCode;
    private String productName;
    private String productDesc;
    private String productUnit;
    private double productCount;
    private double totalPrice;
    private int isPayment;
    private int createdBy;
    private Date creationDate;
    private int modifyBy;
    private Date modifyDate;
    private int providerId;

    private String providerName;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getBillCode() {
        return billCode;
    }

    public void setBillCode(String billCode) {
        this.billCode = billCode;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getProductDesc() {
        return productDesc;
    }

    public void setProductDesc(String productDesc) {
        this.productDesc = productDesc;
    }

    public String getProductUnit() {
        return productUnit;
    }

    public void setProductUnit(String productUnit) {
        this.productUnit = productUnit;
    }

    public double getProductCount() {
        return productCount;
    }

    public void setProductCount(double productCount) {
        this.productCount = productCount;
    }

    public double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public int getIsPayment() {
        return isPayment;
    }

    public void setIsPayment(int isPayment) {
        this.isPayment = isPayment;
    }

    public int getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(int createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public int getModifyBy() {
        return modifyBy;
    }

    public void setModifyBy(int modifyBy) {
        this.modifyBy = modifyBy;
    }

    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }

    public int getProviderId() {
        return providerId;
    }

    public void setProviderId(int providerId) {
        this.providerId = providerId;
    }

    public String getProviderName() {
        return providerName;
    }

    public void setProviderName(String providerName) {
        this.providerName = providerName;
    }
}

3.创建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>
        <package name="com.openlab.pojo"></package>
    </typeAliases>
    
</configuration>

4.创建dao包

BillDao.java

package com.openlab.dao;
import com.openlab.pojo.Bill;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface BillDao {

    List<Bill> selectBills(@Param("proName") String proName, @Param("providerId")String providerId,@Param("ifPay") Integer ifPay);

}

BillMapper.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.openlab.dao.BillDao">

    <resultMap id="billResultMap" type="Bill">
        <result property="providerName" column="pname"></result>
    </resultMap>

    <select id="selectBills" resultMap="billResultMap">
        select b.*,p.proName as pname from smbms_bill b,smbms_provider p
         <where>
             b.providerId = p.id
             <if test="proName!=null and proName!=''">
                 and b.productName like concat('%',#{proName},'%')
             </if>
             <if test="providerId!=null and providerId!=''">
                 and b.providerId = #{providerId}
             </if>
             <if test="ifPay!=null">
                 and b.isPayment = #{ifPay}
             </if>
         </where>
    </select>

</mapper>

5.创建service包
BillService.java

package com.openlab.service;
import com.openlab.pojo.Bill;

import java.util.List;

public interface BillService {

    List<Bill> getBills(String productName,String providerId,Integer ifPay);

}

6.创建service.impl包
BillServiceImpl.java

package com.openlab.service.impl;
import com.openlab.dao.BillDao;
import com.openlab.pojo.Bill;
import com.openlab.service.BillService;

import java.util.List;

public class BillServiceImpl implements BillService {

    private BillDao billDao;

    public BillDao getBillDao() {
        return billDao;
    }

    public void setBillDao(BillDao billDao) {
        this.billDao = billDao;
    }

    @Override
    public List<Bill> getBills(String productName, String providerId, Integer ifPay) {
        return billDao.selectBills(productName,providerId,ifPay);
    }
}

7.配置applicationContext.xml文件

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url"
                  value="jdbc:mysql://127.0.0.1:3306/smbms?useUnicode=true&amp;characterEncoding=utf-8"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <property name="mapperLocations" value="classpath:com/openlab/dao/**/*.xml"/>
    </bean>

    <bean id="billMapperProxy" class="org.mybatis.spring.mapper.MapperFactoryBean">
        <property name="mapperInterface" value="com.openlab.dao.BillDao" />
        <property name="sqlSessionFactory" ref="sqlSessionFactory" />
    </bean>

    <bean id="billService" class="com.openlab.service.impl.BillServiceImpl">
        <property name="billDao" ref="billMapperProxy"/>
    </bean>
</beans>

8.测试

package com.openlab.test;
import com.openlab.pojo.Bill;
import com.openlab.service.BillService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class Test02 {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        BillService billService = (BillService) ac.getBean("billService");
        List<Bill> bills = billService.getBills("", "2", 2);
        for(Bill bill : bills){
            System.out.println(bill.getBillCode() + "\t" + bill.getProductName() + "\t"
                    + bill.getProviderName() + "\t" + bill.getTotalPrice()
            + "\t" + bill.getIsPayment() + "\t" +  bill.getCreationDate());
        }
    }
}

作业三

在这里插入图片描述

1.修改applicationContext.xml配置文件

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url"
                  value="jdbc:mysql://127.0.0.1:3306/smbms?useUnicode=true&amp;characterEncoding=utf-8"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <property name="mapperLocations" value="classpath:com/openlab/dao/**/*.xml"/>
    </bean>

    <context:component-scan base-package="com.openlab.dao,com.openlab.service"/>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.openlab.dao" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>

</beans>

2.修改BillDao.java

package com.openlab.dao;
import com.openlab.pojo.Bill;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("billDao")
public interface BillDao {

    List<Bill> selectBills(@Param("proName") String proName, @Param("providerId")String providerId,@Param("ifPay") Integer ifPay);

}

3.修改ProviderDao.java

package com.openlab.dao;
import com.openlab.pojo.Provider;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("providerDao")
public interface ProviderDao {

    List<Provider> selectAllProvider();
}

4.修改BillServiceImpl.java

package com.openlab.service.impl;
import com.openlab.dao.BillDao;
import com.openlab.pojo.Bill;
import com.openlab.service.BillService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("billService")
public class BillServiceImpl implements BillService {

    @Resource(name = "billDao")
    private BillDao billDao;

    public BillDao getBillDao() {
        return billDao;
    }

    public void setBillDao(BillDao billDao) {
        this.billDao = billDao;
    }

    @Override
    public List<Bill> getBills(String productName, String providerId, Integer ifPay) {
        return billDao.selectBills(productName,providerId,ifPay);
    }
}

5.修改ProviderServiceImpl.java

package com.openlab.service.impl;
import com.openlab.dao.ProviderDao;
import com.openlab.pojo.Provider;
import com.openlab.service.ProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("providerService")
public class ProviderServiceImpl implements ProviderService {

    @Autowired
    @Qualifier("providerDao")
    private ProviderDao providerDao;

    public ProviderDao getProviderDao() {
        return providerDao;
    }

    public void setProviderDao(ProviderDao providerDao) {
        this.providerDao = providerDao;
    }

    @Override
    public List<Provider> getAllProvider() {
        return providerDao.selectAllProvider();
    }
}

6.测试Test01.java 和 Test02.java

package com.openlab.test;
import com.openlab.pojo.Provider;
import com.openlab.service.ProviderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class Test01 {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        ProviderService providerService = (ProviderService) ac.getBean("providerService");
        List<Provider> allProvider = providerService.getAllProvider();
        for(Provider provider : allProvider){
            System.out.println(provider);
        }
    }
}
package com.openlab.test;
import com.openlab.pojo.Bill;
import com.openlab.service.BillService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class Test02 {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        BillService billService = (BillService) ac.getBean("billService");
        List<Bill> bills = billService.getBills("", "2", 2);
        for(Bill bill : bills){
            System.out.println(bill.getBillCode() + "\t" + bill.getProductName() + "\t"
                    + bill.getProviderName() + "\t" + bill.getTotalPrice()
            + "\t" + bill.getIsPayment() + "\t" +  bill.getCreationDate());
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Quartz 是一个开源的作业调度框架,可以用来实现在特定的时间触发任务执行。它支持灵活的调度配置,可以按照预定的时间间隔、日期、月份等触发作业的执行。Quartz 提供了可靠性和强大的功能,可以用于构建各种类型的调度应用程序,包括定时任务、周期性任务、分布式任务等。 Quartz 提供了一个简单易用的 API,可以用 Java 或者其他支持 Java 的语言进行开发。它的核心概念是 Job(作业)和 Trigger(触发器)。Job 是具体要执行的任务,而 Trigger 则定义了作业执行的时间规则。 使用 Quartz,你可以创建一个作业类实现 Job 接口,并在其中定义具体要执行的任务逻辑。然后,通过创建 Trigger 对象来指定作业的执行时间规则,可以是一个特定的时间点、重复的时间间隔、每天固定时间执行等等。 Quartz 还提供了一些高级功能,例如集群支持、持久化存储、错过触发处理等。集群支持可以让多个节点共享作业调度,提高系统的可用性和可伸缩性。持久化存储可以将作业和触发器的配置信息保存到数据库中,从而实现持久化和恢复。错过触发处理可以在作业错过预定执行时间时进行处理,例如立即执行、延迟执行或者忽略执行等。 总而言之,Quartz 是一个功能强大、灵活可靠的作业调度框架,适用于各种类型的调度应用程序开发。无论是简单的定时任务还是复杂的分布式任务调度,Quartz 都可以提供良好的支持和解决方案。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值