ORM框架Bee的使用实例 (直接使用,及在MVC中使用)

一、直接用Bee的例子:

public static void main(String[] args) {
        Suid suid=BeeFactory.getHoneyFactory().getSuid();
         
        Orders orders1=new Orders();
        orders1.setId(100001L);
        orders1.setName("Bee--ORM Framework");
        List list1 =suid.select(orders1);  //select
         
        orders1.setName("Bee--ORM Framework");
        int updateNum=suid.update(orders1);   //update
        System.out.println("update record:"+updateNum);
         
        Orders orders2=new Orders();
        orders2.setUserid("bee");
        orders2.setName("Bee-ORM framework");
        orders2.setTotal(new BigDecimal(91.99));
        orders2.setRemark("");  //empty String test
         
        int insertNum=suid.insert(orders2); //insert
   }

二、Bee与Spring,Springmvc结合的例子:1.  第一个rest类

@RequestMapping("/edit")
public Result update(Testnum testnum){
    Result  result =new Result();
    try{          
        int num=objSQLService.update(testnum);
        result.setTotal(num);
        if(num<=0) result.setErrorMsg("update failed!");
    } catch (BeeSQLException e) {
        result.setErrorMsg(e.getMessage());
    }
    return result;
}

 

2. 第二个rest类

@RequestMapping("/edit")
public Result update(TTest tTest){
    Result  result =new Result();
    try{          
        int num=objSQLService.update(tTest);
        result.setTotal(num);
        if(num<=0) result.setErrorMsg("update failed!");
    } catch (BeeSQLException e) {
        result.setErrorMsg(e.getMessage());
    }
    return result;
}

引入Bee,不同的rest类或Controller类或Action类,用的是同一个Bee实例作为dao,简单的业务还可以用Bee包装的统一的Service.

/**
 * @author AiTeaSoft.com
 * @since  1.1
 * Create on 2019-03-27 17:07:40
 */
@RestController
@RequestMapping("/testnum")
public class TestnumRest {
    @Autowired
    ObjSQLService objSQLService;
    @Autowired
    ObjSQLRichService objSQLRichService;

 

你可能感兴趣的:(Java,Bee,ORM,Tea软件理论,Bee框架及Tea风格高效编程)